{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Sympy - Symbolic algebra in Python"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "J.R. Johansson (jrjohansson at gmail.com)\n",
    "\n",
    "The latest version of this [IPython notebook](http://ipython.org/notebook.html) lecture is available at [http://github.com/jrjohansson/scientific-python-lectures](http://github.com/jrjohansson/scientific-python-lectures).\n",
    "\n",
    "The other notebooks in this lecture series are indexed at [http://jrjohansson.github.io](http://jrjohansson.github.io)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib inline\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Introduction"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "There are two notable Computer Algebra Systems (CAS) for Python:\n",
    "\n",
    "* [SymPy](http://sympy.org/en/index.html) - A python module that can be used in any Python program, or in an IPython session, that provides powerful CAS features. \n",
    "* [Sage](http://www.sagemath.org/) - Sage is a full-featured and very powerful CAS enviroment that aims to provide an open source system that competes with Mathematica and Maple. Sage is not a regular Python module, but rather a CAS environment that uses Python as its programming language.\n",
    "\n",
    "Sage is in some aspects more powerful than SymPy, but both offer very comprehensive CAS functionality. The advantage of SymPy is that it is a regular Python module and integrates well with the IPython notebook. \n",
    "\n",
    "In this lecture we will therefore look at how to use SymPy with IPython notebooks. If you are interested in an open source CAS environment I also recommend to read more about Sage.\n",
    "\n",
    "To get started using SymPy in a Python program or notebook, import the module `sympy`:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sympy import *"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "To get nice-looking $\\LaTeX$ formatted output run:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "init_printing()\n",
    "\n",
    "# or with older versions of sympy/ipython, load the IPython extension\n",
    "#%load_ext sympy.interactive.ipythonprinting\n",
    "# or\n",
    "#%load_ext sympyprinting"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Symbolic variables"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In SymPy we need to create symbols for the variables we want to work with. We can create a new symbol using the `Symbol` class:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "x = Symbol('x')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAEgAAAAbBAMAAAAt2dQtAAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAMmYiu80QdonvRN2ZVKvu110NAAABZElEQVQoFY2Sv0vDQBTHv0na/CBE+w+oWcQ1qJOTKDgJdomDWAiIdBPFQSctguBQpKM4qZPgYDdxEIqzQzcHcXARR0HI4BLf5d21HJamb7j3vt/78O5dckBRNFeTIgRuNFYthPzI+CmEvCvrtxACgnQEyN8dAWoSY4S0DA6zQr7ZoWV+MJC7H7Te4hpYHwKV6aDa+wqchgZtaYo2vSz7hhdp9qum7BbLO82FDqHGu+KC9aOFQ/kxJORkFB1A7FIsAXbDfPCrLCV0NrE/M0fONLtPgJu4aSBHY8joutGe2H9j6JI6obzIAr2ZSvgU1hT7BAHjPNFpHD/G8aZwJtEWSUJ0HNUVJCL3Oz0j//fy7jR4kBzDSXJGHWenyF+RHPwcuO+uYZYZBTltXAjnhW1quHNQPwlZKagU4ks4G2z78u46JJXV4iJ/LtKjdNMvqXL51sCyZutiW8lhj67XwAoV/i+bct4/Xs5GamR386YAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$\\left(x + \\pi\\right)^{2}$$"
      ],
      "text/plain": [
       "       2\n",
       "(x + π) "
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(pi + x)**2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "# alternative way of defining symbols\n",
    "a, b, c = symbols(\"a, b, c\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "sympy.core.symbol.Symbol"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(a)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can add assumptions to symbols when we create them:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "x = Symbol('x', real=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x.is_imaginary"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "x = Symbol('x', positive=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAACoAAAAPBAMAAABgjEDtAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMA782r3SJ2ZjIQmUS7\nVIlAnjihAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAAv0lEQVQYGWNg/GQs72z0hQEV8Acw5BcwNKIK\nMsxiAIkyo4mGg0XZJqAKR4BFOUCi0Q2c3QFwWaAJ3Iq5j0LXH+A9n8DAuvwxWAooysC4dn4B0wEG\n/gSGLRO4JUEaQKJMDgwMPGBROQYGMaAgRNQAKsrxq7zcHC66ACrK/hckBARgExbA1H4DiyFEmQ8w\nxCcwODEwTIOpZQGqZRdguHiSob+AYSUDA/caeZkV3Of/XGBgeJc2RWQCp1XeBKghaBQAM0c287zN\nvm0AAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$\\mathrm{True}$$"
      ],
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x > 0"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Complex numbers"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The imaginary unit is denoted `I` in Sympy. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAACoAAAAQBAMAAACSDPCjAAAALVBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADAOrOgAAAADnRSTlMAVO8Qq5l2zWaJ3SK7RPx7\nN2kAAAAJcEhZcwAADsQAAA7EAZUrDhsAAABySURBVBgZY2DABCwHGBgYldHFWRoYTEIeQ0UZE5Ck\n2SgRNQsDmoRhwoRLWES5BcLhopzl5VXq5eUODAzMDM/gokAGzGWMIEdhmMvuYIBF1E5gAhbRe9wN\nDKxOzz2A5gABzFyWDggfQsJEkcWATtoA5wMA/Fcc5MixWvAAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$1 + i$$"
      ],
      "text/plain": [
       "1 + ⅈ"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "1+1*I"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAABgAAAAPBAMAAAAMihLoAAAAJFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAADHJj5lAAAAC3RSTlMAEM3dMlTvq5l2ZtVdCTcAAAAJcEhZcwAA\nDsQAAA7EAZUrDhsAAAAqSURBVAgdY2DAClgTEcLi7RsRHAZOMjlCxiCgwkC2ATA3cJRtqoKxwTQA\nC0AL2ft3JesAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$-1$$"
      ],
      "text/plain": [
       "-1"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "I**2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAEwAAAAbBAMAAAAkMnRXAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAIma7zZnddlTvRImr\nEDIioekeAAAACXBIWXMAAA7EAAAOxAGVKw4bAAABXElEQVQ4EY2SPUvEQBCG3z0xauKeQUEsg4i9\ngqVwYgqRIDZWWlhYaJcmWB1i40chXm2jlRaClYeVyJ2IpRHs/BHGykPQczYTwq0mXgayzLzzZIbZ\nHaC71WfC7hAse7BSADPs8nsR7Ex8FsCA/q9CmOEXwupECYeOPCvZlCkt0zFC330ehgZlLnEFzJHT\nzMQO6VZfgPLCwSxX1Kh9juTDE2GWj4F2O4KhumuWYMAOYbLGuVENUYGGYZHzAf0R+JDbjYsbVnRs\nhcVp6m/W8IpJfyMLm2BxExjrreAWd+FuFrbH4gkQDvkIMR/H16675bpe7KsR8JZiOFbxB8e/R0gw\nagpP0iV+Z2PnLNMIsmXhqC9ClRV90mQEen0zGjZbPZFwsrBVFlXRpiMfq8E4C+n1rp16DrDE6j+P\npQCxzli8TOwm53NnRE/PNtWp/vFpkdjUWuZbWkQ4+RDiJaf8DywZUcb5dpcnAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$\\left(i x + 1\\right)^{2}$$"
      ],
      "text/plain": [
       "         2\n",
       "(ⅈ⋅x + 1) "
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(x * I + 1)**2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Rational numbers"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "There are three different numerical types in SymPy: `Real`, `Rational`, `Integer`: "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "r1 = Rational(4,5)\n",
    "r2 = Rational(5,4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAAsAAAAqBAMAAACXcryGAAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAMpndu3bvImbNiRBUq0Qb3U6NAAAAkklEQVQYGWNgYGAQAmIgMAGTrClgqmIKmFoApjgKwNRWBjC1AEzxCICpXQxg6uzdu9+ugnVAtDN8AXOW/L8Bpski/oPAB6K0Tt0g9ACoMP//V5DyWVcLQNQFEAGnbrQqgnjeDPUPQDQDiwGYYvrOwMA7gYHrHwMD2wQGpt8MDEwMDMwTGBjYFRjaQMYUrdVmYAAAOF8pKUDr98cAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$\\frac{4}{5}$$"
      ],
      "text/plain": [
       "4/5"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAABUAAAAqBAMAAACuFQ3dAAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAMpndu3bvImbNiRBUq0Qb3U6NAAAA6klEQVQYGWNgYGAQAmLODUACCEwYGNj9IWzWFAZup/sQdsUUoFw8hL0AweYoQLC3MiDYCxBsHgEEexcDgn327t1vV+FmMqQgzGf4gmAv+X+DQTfftgEoQmPwHw4+UGZTkYojA8OmpYpAU7gvMKx/wDCHYXMBAwPvBga2BI4EBq4JDAxsBgy8H1kuMPD8Bgb8byCb/wID3x+wtcy/9ysw8H0Fs98vqF/AwPgLzDZhgLOZHBj2L4CqiWVg4Fdg4AHp5VFgKGd2YOAAmgmK0XDWBAYmoF3sVqt0DRhsGLYJAO0C+tGAYVfoRQYGAGg1Ulux6DimAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$\\frac{41}{20}$$"
      ],
      "text/plain": [
       "41\n",
       "──\n",
       "20"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r1+r2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAABUAAAAqBAMAAACuFQ3dAAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAzRAiu5mrdu/dZokyRFRd1xrCAAABAklEQVQYGWNgYGBUYGBg2F19AEgy+wPZihdYBRgYmFzzgWxpBhYHoDhDvQID12cQAwiAbJYGIA0CQDa/zPZYGFtfioHjAVRc/xMDaxOUzT+BgesvlM0hwMD1C8pmaUCI8wHVN0DFGbwZNB4A2WH90xYwcIfmgIRpDP7DwQfKbDIN8WFgEFc4egEYhgkM+y8w9P//DjSRTYGBo4FBOt0AyOaYwMD2hyEBbA/jJwQbKMD5iSFreQxYhuH+BgYnBnugOUAwBUSwTACRrA5gEhwdZUCDBRi4QWHLF8BgDAxb1k9A9lEGhmJWoGECwCidvTtsAnMAwwqgxYxAP05gMN0WxMAAAJ3jRrgsItfHAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$\\frac{16}{25}$$"
      ],
      "text/plain": [
       "16\n",
       "──\n",
       "25"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r1/r2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Numerical evaluation"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "SymPy uses a library for artitrary precision as numerical backend, and has predefined SymPy expressions for a number of mathematical constants, such as: `pi`, `e`, `oo` for infinity.\n",
    "\n",
    "To evaluate an expression numerically we can use the `evalf` function (or `N`). It takes an argument `n` which specifies the number of significant digits."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAgsAAAAPBAMAAACYf5HCAAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAIom7VJlmdt1E7xDNMqsI8sYEAAAGp0lEQVRIDe2X7YtUdRTHvzO7M7vOnZmdCiMqaJnYjEh3ygIryiGod7Wb4osedG9BChbtFEhQllvSu9B5E0EEKkWU9nApoqhol6IipBwEoReRA6VGD65P+bSb0/d8z2/GW39DF7x77jm/8znfc+69v7kCF1ZvgI5iYn/28Z9ZxadL9yJasaGCzKqlLTqrT7TwTbKviUz1ynoIPznSBD5cdA9KW1ZUq7I87DlCf/TEvV1udtHiQDOLB4tpjZCR0WRh4cpb08iuFsqwCIQM3NI4ObvhUl2G9MNKuH7T69pMqpf44UC1Oiyut5sZx1hMEjLLE/uzOViFTqeBT+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0dhV76NyV3OPQ1MNhWRFYqF8jsTp3l2rsbkNHLiMj4N9lIwIqROuKs3hiDVcnR7vZjrN0HSlhI4MGMr2YQvz1TQxy548FF6H70x/MFtgZoxm2CgzX5mkD9ZnrFPiAuA5XWFOb79dfAd44tst0+Wwhho8/vD0IUEpRPOfZtjiBWRJaeXV45ono1nwaOHVDHuDWN1WERInaLh82OQVM9hJ7ZXsJg5A1Iq7eTX9rSK62MYmkOf7XC6uvvw4bOH3E/MBGn4HriDDfGXIn+mMIPcHPi4LY8t/OkR9h1zTbGN6Bz/ylJYOULbU3rQudy8+TQYTZacXt5yHhHNs/vHKfY8Ulo4lMkEFhFSp/7Dh2ffbegHk2Uo1XM2UbgXM6cjpS0lcLqtUU1wqS0v1DB4lAy/Al4L1jjwItZXSkdRGsdApZ97w/YcX+wZW7G1ovAO7hWV/A7sr6DEm+WWwsoRulABriOT7jHuDU6TJaeXV45osuwj+/EUUsWeAr9BFRGyyyVAY5BU5XgnKiGnkNKWEoj9hIrry/Mxxhr8HuqOgZ8KGs9C62pj8lmMS6ojvwLX45M6v3zXV7AW/af4yczwqwnWYWB39DV/7TkGtxRWjtALdiPfIJPcvuHodafJklNrHCmasjPPV9dMpZAqNliP3oEiQna5Q2EMkqoc168ScgopbSmBGOMMxA2Nv7TqJmALsOa9LTE/DDsH3cqsOMAfQ4vt6XS432RX/cm8Jffzp3DVSv4XyMKlAyNNYISXyNhPoSyFPUfon1bwg0NcjKxpBZpZ7tQa5Ygmq8gP/qkUUsWiRc+24BEhnZtdfi7O/Xb6oEv1HO/ESki/kK7tvEBcWqdoayI0Tjn/H/8ADtF52HEjSsAAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$3.1415926535897932384626433832795028841971693993751$$"
      ],
      "text/plain": [
       "3.1415926535897932384626433832795028841971693993751"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pi.evalf(n=50)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "y = (x + pi)**2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAHUAAAAbBAMAAACw1N2lAAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAMmYiu80QdonvRN2ZVKvu110NAAACK0lEQVQ4EZ2TP2gUURDGv7vL7q17WXONkC6rwS6QQ9MYAi5qY3XXnIU2rxCCjV5nBDHrH0iKIAhJYUDdViwUUqSJuEUUAhJWsBVFsLCJErhYBDxn5u3bS2QjcV/x5pt532/f7LALFFvO+rtiIFH38a0wu4KRRlF4GWejoizwWRVnV4ujTkxsyaftf9ZxMY/xPpHHVeYfJLp+iUMppo2VM3cXR+sk3NClIIeU7VtT8LalMLHDoRbQHaTsy3gLtKhy7NNHhWpIKlt2Q8vZBLusrm4KeyvQygpxAZihg2e9HnAkdWvG6+j4PLK7oqrMVk4GAKtxMV/THuCFERINC9OzsI6VshfFZCUps0Bx+s7kjL6wz1qxGIQdNWx3+HZEA9NHwDmaQFherbXEmrHDa5JLp3YnZe2ujydAWXuB1/Qc5ex4jf0snEdS4HsdGLansKHgvdLPxTLdK2d/sXisuMLsB8Py7McjlH6KF8wCQx3enXb7ylK7HZM8DTQTrhFrhxm7RKzfZ6lnYKQOxRHmfam5ps8FYr2trR9PO9IBzZnudU3PNCtPzaKq2Jmxi8CbBhe4Z/oIAq3ov9vYM6uHwMukiVNs6bMn4P3CjZZhhwKtBkKb5jwYs5UWfRvXb07f8yXJ7nXfr0eofcHg992vNIjmb1+rhc06YEXajJq0liYZa/LceMZUy7FRHF1/b3aAnsvq5zN1SGHTGNKV+++bw7w40H/Lip9n+Edt1Jz9AbLJiWXESsPWAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$\\left(x + 3.1416\\right)^{2}$$"
      ],
      "text/plain": [
       "            2\n",
       "(x + 3.1416) "
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "N(y, 5) # same as evalf"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "When we numerically evaluate algebraic expressions we often want to substitute a symbol with a numerical value. In SymPy we do that using the `subs` function:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAFYAAAAbBAMAAAAUvmV2AAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAIma7zZnddlTvRIkQ\nqzLsm4+cAAAACXBIWXMAAA7EAAAOxAGVKw4bAAABlElEQVQ4EY2TO0jDUBSG/1QSLUkfKLqaQRA3\nLbh1qBBQlEoXJx901EGog651sro5u7STiyAKdlQiuFsFcdRFcFNBFxXiOffePBpEcyDn8Z+vNyfJ\nKZDQ2pNuQhJmPlNKyhr57FtitqV9JmWBvu/krFFLzrYJ1Wxyf1oqT+1UhdxAyE27T9thFWY3lB7h\nGJiiZM8Vjab3JWLcXQHZmd0in23dPUh27p7vxtaQQXmzhrTnvcLgdt0Vakf14qy1LxtDHP5hMSvZ\nzQh7O7oixWCGuud5H8CClAsRtojhllTVvOZFo3+DhhyR6mqEBXqqXAbzPuO095HKHbrIDtipeQGd\nl+nMcdYcp8wNjGdc8i+cdrG0oaZaJv+dZTsGQ4qNzJAuQVfL5LO6nXOJPeQfAJFn0wGjJMTgPVy7\nuRYp6tl4fXhe6x1aBWP8Zcj8c7eQPqFyUYji+OVm2cY6MHi+JMWALSDD7LyUxTdWRBj8c6WiVWUU\nexlCKrvsUmh3pE10yb8WtJPSIrvuS/EYHKfZ8Va8Fv8hEn8A9AZYsVBvIRkAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$\\left(1.5 + \\pi\\right)^{2}$$"
      ],
      "text/plain": [
       "         2\n",
       "(1.5 + π) "
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y.subs(x, 1.5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAKAAAAAPBAMAAACRq9klAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAIpm7MhCriUTv3c12\nVGZoascqAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAC7klEQVQ4Ea2UTWhUVxiGnzuTOz+ZmWTMRqwL\nb2MbFREjNqCCJGRhoZvclQtpyRCo+JsMURwU0UvBhbqIUiKxRRxc6KILZ2PrQnAMlFJoyVBKoRu9\nbhRRoqLRmDG5vufcaTbdeuC+95z7fueZ7zs/g9O9dYD/Wu7Xtk3qt3ktWVnZCV//th661n4BTuVI\nA9Inj7birXPHH2zg/jEe8NVIpVJmN+l5KEzamGwUldVp743F8XgQ4pFquCVOB3RRWMK9zUbZ//pY\nh6vRW0jAYZ5HUVTiW7jM7p45xUDu2D3z+t0AJflFOquFEKeW8sleYKbBAkmPrbgjYz7W4ZdDRbgP\nq/kUUvADjA2Qj4EaqzlPBTSSmWK4lu7FrWarpF5zNnCbTGi+2oyPdSiZ0RHYQxm0GHf9/wHTOQGt\noJIzr/x0mJszQC3NEtsNwAKtEwMn+jilj5m6sbjpL2c4Oz0ADw3QCu4NFbBkYmk3Rewp0/xyOlBP\nGcbO6LPPVGr0ONTHpB5htaitkpO+M49bF9AKzonPlWt0y4RNlGHlNd9thlzR0ACt08eaAE43NbZZ\n6qdLy0B920EaAa1oeDzgn3PvAvWu6yE95UY+GzTZAFtOskph380pcF+YGLr1tDJUb3PxbwO0omF2\nsqPEzKQOhqeRToS/AM8DC2w5JF7yiPw7LVzNhOQ9I/EuH1TuZ8oCukZwiiQXs0XaFmFaUSugv/GT\ngKEFWidVMwf5Igw14vPLX2ZeC/ijMvxm796xS38aqXfOCTgs0igFTzhV29/Yv5yhdbI1EnOm1lTI\ncEmxumb5ZaAHSoBsbyx6t79UHmxhEO7xvU5EcUhrKFtraJ2ENqFmMkwWGdJ8PqmMH4hLHq7pbnXI\notMAJR0hD+qZW3TUnRuVniqzFN6TKrutXY4djydFzvs806E1wLtRtEBif3PU7LazbsTXVva/CWP5\nrnsb7Fq3npyuaZVM99oAxnsGoOfqz6F16Dqmo9U2oj8HVjUE/NjtA/9e98ZPxvCDAAAAAElFTkSu\nQmCC\n",
      "text/latex": [
       "$$21.5443823618587$$"
      ],
      "text/plain": [
       "21.5443823618587"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "N(y.subs(x, 1.5))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The `subs` function can of course also be used to substitute Symbols and expressions:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAFIAAAAbBAMAAAAdVcUMAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAIma7zZnddlTvRIkQ\nMqvFy5UvAAAACXBIWXMAAA7EAAAOxAGVKw4bAAABm0lEQVQ4EY2TO0gDQRCG/8vrEu9OToSUkkKw\nja/OQuEQESRBCBZpUlppLGwEIY1ip4gIPgorQUSwSRWEFNYmpZXGRgsFY2OhgXP25nY1IZGbYmfn\n/7/sIzsHBIryZDUQB8Punw5GxmzrIyB5pn0FI4F4KygZKwYlywRqKRr+iZBNZihLw2A3SsuN16X+\nRJNLXAEzUvmb72Coy94C1tzOFK+roLh/8DfgSIpGEQnXbSImjqFCkofAu9ze3GM7qSgxkWSm+kti\nnpF1Slp+6ZQrSVK1WtVdiiyQY2+M0oUdaXaSfd+o3K+NDJA+zN4yYO4jmu4kYw2rZNibQt5m7xiI\ntuA9luE4sweO0/AMsWUY9B8Aj54AIhNp1OpcqXPqdD48oCBkn6Tda9fYFQqFIreg2ViE10Hn7NGN\naiVMxO020spCt80WvIfyb0RNEimGVgz+nVwzWSk/Qy/gRMh59mhp8+VmaKOdzLjuJ8IpvAp5gb3u\nr8kej1qBs9d5yjD5uKoWE+oQjlE/90zUdRxdO1maIqultJQoe4f3dZD9A6SlVff4q7eXAAAAAElF\nTkSuQmCC\n",
      "text/latex": [
       "$$\\left(a + 2 \\pi\\right)^{2}$$"
      ],
      "text/plain": [
       "         2\n",
       "(a + 2⋅π) "
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y.subs(x, a+pi)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can also combine numerical evolution of expressions with NumPy arrays:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "x_vec = numpy.arange(0, 10, 0.1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "y_vec = numpy.array([N(((x + pi)**2).subs(x, xx)) for xx in x_vec])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXoAAAD8CAYAAAB5Pm/hAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4wLCBod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vva3vKOfehhzVJ9XkQeMt3IpMOjPe4nmrnnFtpZu8AaykfZbaOEL1L1szmAEOB5maWAUwGngXmmdkEymf0HV0ln6U7Y0VEQlswd92IiMg5UNCLiIQ4Bb2ISIhT0IuIhDgFvYhIiFPQi4iEOAW9iEiIU9CLiIS4/wcYmv+Je/JRUwAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig, ax = plt.subplots()\n",
    "ax.plot(x_vec, y_vec);"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "However, this kind of numerical evolution can be very slow, and there is a much more efficient way to do it: Use the function `lambdify` to \"compile\" a Sympy expression into a function that is much more efficient to evaluate numerically:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [],
   "source": [
    "f = lambdify([x], (x + pi)**2, 'numpy')  # the first argument is a list of variables that\n",
    "                                         # f will be a function of: in this case only x -> f(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [],
   "source": [
    "y_vec = f(x_vec)  # now we can directly pass a numpy array and f(x) is efficiently evaluated"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The speedup when using \"lambdified\" functions instead of direct numerical evaluation can be significant, often several orders of magnitude. Even in this simple example we get a significant speed up:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10 loops, best of 3: 28.2 ms per loop\n"
     ]
    }
   ],
   "source": [
    "%%timeit\n",
    "\n",
    "y_vec = numpy.array([N(((x + pi)**2).subs(x, xx)) for xx in x_vec])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The slowest run took 8.86 times longer than the fastest. This could mean that an intermediate result is being cached \n",
      "100000 loops, best of 3: 2.93 µs per loop\n"
     ]
    }
   ],
   "source": [
    "%%timeit\n",
    "\n",
    "y_vec = f(x_vec)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Algebraic manipulations"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "One of the main uses of an CAS is to perform algebraic manipulations of expressions. For example, we might want to expand a product, factor an expression, or simply an expression. The functions for doing these basic operations in SymPy are demonstrated in this section."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Expand and factor"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The first steps in an algebraic manipulation "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAMEAAAAVBAMAAAANw5eWAAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAMmYiu80QdonvRN2ZVKvu110NAAACwElEQVRIDbWVu4sTURTGvzxm8py4WFkIxhUrLYJuo2wR9Q9ICsfCBwyorDYSEHZT7QbxsYW4EbXQKtiIWGxARQXFFFsuS0DQwmbVQuyiYCwWiefcRzJnnbiVt7j3nnO+8/vmztwQ4P+PWHGcx25T2D5OEJ/QlVhxnEIhpqKrJ4CCBiTKUYrplSPAJ12JRCQWr3Y1glARY6pPyaoqOEFE3V3HUguOrkQipuH9UIhUI9zvlnR0bo0d6irQs1Wd1ZtCgEwTulkiYBQLXWwoRMYwdaNXM6QUO1xUwR2T0ssHvWTaKHyH2+RIImAUj1vuT4V4ojvMLB2cLqWzbaEw/U6fHXCGaxJhHaDeEiFukmRm/nBdP7x0SHeoyJM79+XRDdrTMA60y9ExuXsTYqRwOqr7KPU34i9yVdZCOsQ5mSwCF7Cv9pzrYYflBrCXUxIxdNjxmmqEeEM+QbrvlVi7ycFrUyrXBa5jKXinBMN+4BklPnJSIkaK9G0CtvGAzgCnzEoa8gyxHqUyLSDAca7yGL6lfJmiXZySiJEC9wMQgsrAthrPad8/dc/3O7xXd2noAPziJK75/ivfP6328zxbB4sIKQ4ClS470BFJOEGPyUOeQV0jfkuI0c1UguETeh0QQ10jibCKQYBKkW8ifSYvWEAqUADpMPzS71M9zEqHncDl0ZcOIazDXeBtib/0LWC5W8EB3S8d8h3KpteR/Z3sJYpaYb5D4uXiWhtY5aREWIdJePRqCUHnvDQ3c8X0W4f8t43PgNOC+sW5X2frk7TlYRycwWBADic5JRFWkV1daSlErsQiO6yDjg+p5aktqtU46FyiyatEWAetIES8o7d6zhbDkf4Z7w+n8DAcpWscSYRUMOJYuEXs3aoKk+KUQnFeR1sgIv8+wuhEWVDDgUFvgbCXJNyp93tMytyzvwVxc7p/Iv4AakC5V6GQHjwAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$\\left(x + 1\\right) \\left(x + 2\\right) \\left(x + 3\\right)$$"
      ],
      "text/plain": [
       "(x + 1)⋅(x + 2)⋅(x + 3)"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(x+1)*(x+2)*(x+3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAKsAAAAWBAMAAABNknGBAAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAEHarIkSJZt3NVLsyme8Q6PJIAAACMUlEQVQ4EZWUMYgTQRSG/4253VyymywRBBHi3gnpRBDhGpFtxMImWFgJxj3QxmA67U7s7KKgXtQigpWNZ2Mj6la2HhwWFspdeVaJeHh3CHF2dt7sjJvZwy1m/nnfvH/ezj4WSJ9o2RcqP/Xem1l+txrx+t6aula1HR4aqOv/0F7XGZu2V0L3l4kdGPeMFdU75Z0D000bWrGJANWJmRWT5sMCXgkKYDHKfbLr7ZgyeiTk/CBRfJAhKezoptRw9zOdqKMdedvOuo6Ai8mt8OFfAliP8JWirbj8O9VWmM6PUVsT9DKu6OzYBrPlg9iRTJQ438U7CldCZyvV1YDPTtZT7tNXbzQGlJJq+ZCCZBSJWAmzmBsti5WgtU0J69Op6GnKLLT9kCY2T5xvB9KDDm08j74As5lSrbV45lKUJtOZe59OdtiVdJ17lUHO9vgT1EcGptgewZ3gvmZr7fXxA7B9e1IN87YTeFsGpthewy3/pW479fHdh4V5+uIci3dp3IWzY2CKrY9nVBFdwi6wwm4BjYAI7OFwdXs4XAfqAzis5WYyxRb4yZOzRGwz2z4Lfo7hS2P6ZKwTHPaDmclUW/cPe1/+ULWsE1i1Vf8USnlb9nfxNg1MsX1RGmNBt33N7ha4OvqIC1mxVC3eojUyMdm3c/u1cTl5Y/ZQtbWuxTrh8GLzhgAatb+dNTLv3O4SksE6vdC+zdMyW/Q2YhFSJjpUCUlZxGS1crcm5tTSNQIUMR3+BZqsk+Ep3JM5AAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$x^{3} + 6 x^{2} + 11 x + 6$$"
      ],
      "text/plain": [
       " 3      2           \n",
       "x  + 6⋅x  + 11⋅x + 6"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expand((x+1)*(x+2)*(x+3))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The `expand` function takes a number of keywords arguments which we can tell the functions what kind of expansions we want to have performed. For example, to expand trigonometric expressions, use the `trig=True` keyword argument:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAFgAAAAVBAMAAAAwfTS1AAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAMnZUzRC73UTviSKZZqszMyTAAAABn0lEQVQoFaWSzUsCURTFj+nk5CRUBC0CldpVSKuiWiSl1SJiFiEEUZsIwj6k/gF3UiuJqKAWEi0jXLkJwkW0CpIIglYqtBQqKawwu2/GmfcmbNXAe/fce35z530M8J/Hlv3jbXeLbth2OZDmkqvwAem8nts+eT3EpaBmSDuEXJcNSbEkpWpZiaLVYkaTYWuU3acFyG8UpYSWKK16jea4qZgwYFeUZeOwdXcF0t9oP27z+6hwxqqXJx0qiybsKPT1My8MRLEOTPiUL7LXaMhH2GAohxdDIPMe2yqSDF4BKmRv0ZjL4pqhHB5VQQc2COd7Lxi8BLySfUjjVsUmQzl8BYlgL6TTaobByxzeh/RCpCsYnNwLBjMkpyHT4XlxAXdZgGkZ1MT+LBHCO1fQTIcXxzBQFGDaoFRCY2DEApfZPmiDQyoibA21ZZwTNIaHXNICF7FK+Q127h5jnuqTp5of+Mjpl7LQ01mIWeB5PzXGlFYTJmdKSMxL0WpKQrSYdmfEiswaGo/LZygzRkz1W8z+LgB1f34Nq9NGEb8s9nKn8APn2mCn+s4IPwAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$\\sin{\\left (a + b \\right )}$$"
      ],
      "text/plain": [
       "sin(a + b)"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sin(a+b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAP8AAAAVBAMAAAB7+SUdAAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAMnZUzRC73UTviSKZZqszMyTAAAAEK0lEQVRIDc2WUWhbVRjH/9fcm6S5zRK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G2ixPOa3DbajOA1C3lX2BXE7/y3Y+tzau/bl49d8ffPZ5XE9g7fP1cC3iAS7H3zAn4Z0+2sh/efpxTwXu2dKkU5T00INg5v/LI+ZVrxt5hlAfknZmncFv88P4YDvDJ9G9qM86Fzr176pYIM2KNg1r7E1rZd40NDQ3YKaIzQRSZXU/WUCTgn/WKXEkr+66xoa/a1Oh8J5JTJmQJQ5GA5aTVeNRaEUuNk2mcdyCUXiUOWSqiSMJ+I0rUSdY6So2TaZwb/eTQfmOglP5Bkog/DZPzuhLr1ob4StQk+10lfzKBNSKiIP4PvzMnUkUr/wUAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$\\sin{\\left (a \\right )} \\cos{\\left (b \\right )} + \\sin{\\left (b \\right )} \\cos{\\left (a \\right )}$$"
      ],
      "text/plain": [
       "sin(a)⋅cos(b) + sin(b)⋅cos(a)"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expand(sin(a+b), trig=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "See `help(expand)` for a detailed explanation of the various types of expansions the `expand` functions can perform."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The opposite a product expansion is of course factoring. The factor an expression in SymPy use the `factor` function: "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAMEAAAAVBAMAAAANw5eWAAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAMmYiu80QdonvRN2ZVKvu110NAAACwElEQVRIDbWVu4sTURTGvzxm8py4WFkIxhUrLYJuo2wR9Q9ICsfCBwyorDYSEHZT7QbxsYW4EbXQKtiIWGxARQXFFFsuS0DQwmbVQuyiYCwWiefcRzJnnbiVt7j3nnO+8/vmztwQ4P+PWHGcx25T2D5OEJ/QlVhxnEIhpqKrJ4CCBiTKUYrplSPAJ12JRCQWr3Y1glARY6pPyaoqOEFE3V3HUguOrkQipuH9UIhUI9zvlnR0bo0d6irQs1Wd1ZtCgEwTulkiYBQLXWwoRMYwdaNXM6QUO1xUwR2T0ssHvWTaKHyH2+RIImAUj1vuT4V4ojvMLB2cLqWzbaEw/U6fHXCGaxJhHaDeEiFukmRm/nBdP7x0SHeoyJM79+XRDdrTMA60y9ExuXsTYqRwOqr7KPU34i9yVdZCOsQ5mSwCF7Cv9pzrYYflBrCXUxIxdNjxmmqEeEM+QbrvlVi7ycFrUyrXBa5jKXinBMN+4BklPnJSIkaK9G0CtvGAzgCnzEoa8gyxHqUyLSDAca7yGL6lfJmiXZySiJEC9wMQgsrAthrPad8/dc/3O7xXd2noAPziJK75/ivfP6328zxbB4sIKQ4ClS470BFJOEGPyUOeQV0jfkuI0c1UguETeh0QQ10jibCKQYBKkW8ifSYvWEAqUADpMPzS71M9zEqHncDl0ZcOIazDXeBtib/0LWC5W8EB3S8d8h3KpteR/Z3sJYpaYb5D4uXiWhtY5aREWIdJePRqCUHnvDQ3c8X0W4f8t43PgNOC+sW5X2frk7TlYRycwWBADic5JRFWkV1daSlErsQiO6yDjg+p5aktqtU46FyiyatEWAetIES8o7d6zhbDkf4Z7w+n8DAcpWscSYRUMOJYuEXs3aoKk+KUQnFeR1sgIv8+wuhEWVDDgUFvgbCXJNyp93tMytyzvwVxc7p/Iv4AakC5V6GQHjwAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$\\left(x + 1\\right) \\left(x + 2\\right) \\left(x + 3\\right)$$"
      ],
      "text/plain": [
       "(x + 1)⋅(x + 2)⋅(x + 3)"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "factor(x**3 + 6 * x**2 + 11*x + 6)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Simplify"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The `simplify` tries to simplify an expression into a nice looking expression, using various techniques. More specific alternatives to the `simplify` functions also exists: `trigsimp`, `powsimp`, `logcombine`, etc. \n",
    "\n",
    "The basic usages of these functions are as follows:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAMEAAAAVBAMAAAANw5eWAAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAMmYiu80QdonvRN2ZVKvu110NAAACwElEQVRIDbWVu4sTURTGvzxm8py4WFkIxhUrLYJuo2wR9Q9ICsfCBwyorDYSEHZT7QbxsYW4EbXQKtiIWGxARQXFFFsuS0DQwmbVQuyiYCwWiefcRzJnnbiVt7j3nnO+8/vmztwQ4P+PWHGcx25T2D5OEJ/QlVhxnEIhpqKrJ4CCBiTKUYrplSPAJ12JRCQWr3Y1glARY6pPyaoqOEFE3V3HUguOrkQipuH9UIhUI9zvlnR0bo0d6irQs1Wd1ZtCgEwTulkiYBQLXWwoRMYwdaNXM6QUO1xUwR2T0ssHvWTaKHyH2+RIImAUj1vuT4V4ojvMLB2cLqWzbaEw/U6fHXCGaxJhHaDeEiFukmRm/nBdP7x0SHeoyJM79+XRDdrTMA60y9ExuXsTYqRwOqr7KPU34i9yVdZCOsQ5mSwCF7Cv9pzrYYflBrCXUxIxdNjxmmqEeEM+QbrvlVi7ycFrUyrXBa5jKXinBMN+4BklPnJSIkaK9G0CtvGAzgCnzEoa8gyxHqUyLSDAca7yGL6lfJmiXZySiJEC9wMQgsrAthrPad8/dc/3O7xXd2noAPziJK75/ivfP6328zxbB4sIKQ4ClS470BFJOEGPyUOeQV0jfkuI0c1UguETeh0QQ10jibCKQYBKkW8ifSYvWEAqUADpMPzS71M9zEqHncDl0ZcOIazDXeBtib/0LWC5W8EB3S8d8h3KpteR/Z3sJYpaYb5D4uXiWhtY5aREWIdJePRqCUHnvDQ3c8X0W4f8t43PgNOC+sW5X2frk7TlYRycwWBADic5JRFWkV1daSlErsQiO6yDjg+p5aktqtU46FyiyatEWAetIES8o7d6zhbDkf4Z7w+n8DAcpWscSYRUMOJYuEXs3aoKk+KUQnFeR1sgIv8+wuhEWVDDgUFvgbCXJNyp93tMytyzvwVxc7p/Iv4AakC5V6GQHjwAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$\\left(x + 1\\right) \\left(x + 2\\right) \\left(x + 3\\right)$$"
      ],
      "text/plain": [
       "(x + 1)⋅(x + 2)⋅(x + 3)"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# simplify expands a product\n",
    "simplify((x+1)*(x+2)*(x+3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAAgAAAAPBAMAAAArJJMAAAAAJFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADHJj5lAAAAC3RSTlMAzRAiu5mrdu/dZmiL4QAAAAAjSURBVAgdY2BgEGJgYDDZxMCgEgYkGNhJJVgzdmYB9TEwAACPpQrvlUCHcAAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$1$$"
      ],
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# simplify uses trigonometric identities\n",
    "simplify(sin(a)**2 + cos(a)**2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAD4AAAAvBAMAAABJZWRJAAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAzRAiu5mrdu/dZkRUiTJPL/blAAABcElEQVQ4Ee2RPUjDUBSFT5Jaq7GlQ9E1i+giZhSnCgpudio4WRB1UkMHOwUHcdVK0bkgVXQQN0eDuhtcHBsdFOrQgog/iPW+5uXVxFJXQe/Q951z3ru53AL+kjS/Dihlqm0uTyy3zYHV/zywUr/8YT/pzZ2i/8FfV/X29RvXU+FDHbUeTklyP+wwULkSh6R5GGfQ7ynvND1Ag0pCclgTxiBRz5OQLqh5YUgWsPc6b2HfNHCzfr9iUBRNAXJu9uTaRWxTjwLSQMJQHikPFYEhHBhbQDcbkOUbONUwCbyR7rKAK5S1c/LZpyhHzJzRMQY8E0eOAQ0JIsRq9EO5nNCrDsabuUtebkh5VG81nrP+iH1AptWx/r2wh21cPjg8Z/OdddaQ5fNNw44kUa5476MZqO+hmkLXOlL0PryoK3O5gb67+tLFS6bRVF7ImocUSTTq9yoIa0TQV2j+IbTCFhXSuSnHW6SAkuS2uBi4Nsr1Lp2fe4l4hDH4kW8AAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$\\frac{1}{\\tan{\\left (x \\right )}}$$"
      ],
      "text/plain": [
       "  1   \n",
       "──────\n",
       "tan(x)"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "simplify(cos(x)/sin(x))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### apart and together"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "To manipulate symbolic expressions of fractions, we can use the `apart` and `together` functions:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [],
   "source": [
    "f1 = 1/((a+1)*(a+2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAIIAAAAvBAMAAADdrw/+AAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAVO8Qq5l2zWYiu91E\niTJVJ+QZAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAB/klEQVRIDe2UP0gjQRjF37pu/phEjgMLK0EL\nz1NwCekT7lAEC1OohSCGAzvlUohBLJJWbLbQ5mzs7k91gtgqtjY2sVPS2ikWFnca38xs3Gwcs0UQ\nhGSamfm+37z55u3MAm/ePtqtbWFOzLSoAHzvKMiP0PFB3cV34MPs+FqptYfRWd1mDlRbbW3mV7Pj\nRkuvZbdUIhD48ZoAuh2Z0gLRuT+VGrChVTCGADMvU1oghcR/F4hk6xWMnJqlZu84uBATPfAVGHSB\nmCpVLURNASGhkBRRPTAKzFQUsOeuVZ1fIXzCqB4o2kJBAsuEoovzPLZofgVLnFAA2C1/s0XvAcCx\nDQn8YvjUCd/IvAfIU0TyjAogPoJiA4D4Az0SwAE9/wRrn0M2fw3GX4YIIFnCgkjXAYhlOBPAGGDd\nIZbjMFEobA4XCsxAOdl7wxEBLNk4YlcPYI6BGtC1j3SFczZ/DTUAn2E+NgJZBiTAItPnGFD5BoW4\newrzAYYoh+15iz5EHUiARqU/4Kfh+AGfk+YtevL9PqA3i5CjnCwD4VzkMCHz3hZSwTpnlADWsZ0R\nY6+GvcvyNB0UwTN+i8mrnRWZf1awvtxPUbrCKAGkVq8nT9h7CsVq9Z8L6C+tpNV1DAT8D8dUdigB\n3cvSAPjt4i8793UHAtofiJTrUQUFAoE/sebAE+USwojXIqQHAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$\\frac{1}{\\left(a + 1\\right) \\left(a + 2\\right)}$$"
      ],
      "text/plain": [
       "       1       \n",
       "───────────────\n",
       "(a + 1)⋅(a + 2)"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "f1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAI4AAAAsBAMAAABBB53eAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAEM3dMlTvq5l2ZiKJ\nRLuWvIZ2AAAACXBIWXMAAA7EAAAOxAGVKw4bAAABsElEQVRIDWNgoCEIEyDGcNZE/KoYK+qJMUe8\n/SN+cxgY5hNjDgPnqDl4A3I0fPAGD/3ST3u++gL8TgHJcpR9qiKsarCrYJ1AHReOmoM/HAmGj5Ax\nCKgwMPzHDj4AzedRUlJOUlIqADL5sav6j98VCFmC7kEoxcsaNQdL8OzoewITpSR8GAsYzl+AGsS4\nAWYiJo2zoo+EqGUXYGBLwNQGF4Eqw13RQxWwGTCwf4HrwmRAleEuqKEKmD6SZQ53Tye0RQOziIGB\nGbNNsePENAGI22DK0CrWaxuYPqAqYGC4fwDdO7zZDPpQMezmMGYxcDyAqIApYGAwRzeGQWwBQx9e\nczg+MjBPAKo4pKRkpqSkDlbL0QDVgqD6BRgsQTwkZaj+YnvAIO8AUQ93zwwIH5nMY2CExSFMGao5\n8gcY4qEaYApYGxh2I5sBZDP+YWCFhiIDTBmaOQEMj1g3gLXBFHgwMMxGN+crA59CNEQQpgzVHKYJ\nXOY8KAq4bc60G6CZw6DJsLjgAIoytHTIWHlk+1wUBUzAMhTDHPE53pUXUJThruhhDoYox0kSVCaN\nUyuKBLIyAOpdmg617KB4AAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$- \\frac{1}{a + 2} + \\frac{1}{a + 1}$$"
      ],
      "text/plain": [
       "    1       1  \n",
       "- ───── + ─────\n",
       "  a + 2   a + 1"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "apart(f1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [],
   "source": [
    "f2 = 1/(a+2) + 1/(a+3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAHwAAAAsBAMAAABVvsF6AAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAVO8Qq5l2zWYiiUS7\n3TIuwQ1sAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAB30lEQVRIDe2Wv0sCYRzGHzs0zx8ZQUGTUENF\nRRIuTSdF0RIKaUMESWMNNUQ3hf4DwQ21BIEEEQRFBO01NdQQEQ0tubYpDpFR9nrv+173+l4m1NDg\nDfe+3+d5Pu99+eqhwJ9dHZFGjnL1OqaUyXgjeDRZcsSB1UZweJq4PL/m6OSZiMp3X5vkyHpWTDpV\n7vGXaSf9H2qu9K+aauJ1xldxvgoE8en6Zp+ux8g25Jyq1Dm4ajUn/8OAauzdo0uu1BmdmrrJ85h9\nVRMIZ5mgGHZH2EfhexOELlp5igjdCoZQ8IYmgB7BYLh/ENqaYAgFx4eBeN7uMJxIVvN2m+05nomY\nuDo/x36xLVx5lLGdg6WIqXKcFE9EOTNaCzTNcfV4VsL9A8hQ8Qv3lwGlH+4LEQf2T2v50SwWavFg\nDHCXEEwT41DX73R9nUZapD8gixE8EM/2EgIpIrRcQMtTiDWvGggUqfJ1H4LyQSureU+CCFoOYZZi\neKgk40oZLjYhC+8EeZDWjiuXYR7AcNJP8JWdyBeliMBat1lxvC0Bj4HWtPfeR1MM92YRTnOOrxvY\niuXMguN7RwczZPJTJ9srNMRwnKeuOWWt0eXnKfpxcDxTqbxbdnXDcUGUCo5LxpikOAnCS/gJnQmX\nnOfh0q8AAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$\\frac{1}{a + 3} + \\frac{1}{a + 2}$$"
      ],
      "text/plain": [
       "  1       1  \n",
       "───── + ─────\n",
       "a + 3   a + 2"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "f2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAIIAAAAvBAMAAADdrw/+AAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAIpm7MhCriUTv3c12\nVGZoascqAAAACXBIWXMAAA7EAAAOxAGVKw4bAAACs0lEQVRIDe2WzWsTQRjGn02y+dpuSCMo9LQk\nYC9KK3pS0OhfsKdCvSQIXrRgiGIugrnWi5YiWAsSPNSDivVqhKQFUU9G/wHr1UPpwdDi1/rOzs42\n231NFkoPgnPYd/eZ3zz77uzMvguEW6F0KiwCxpvEcU4Pa3oVt5thGRnHqTEyIyVtZO4N6GZXXhg3\n1wbUYaeZFpLfBgDlkBzQhp8a/f06kH+2D23y2H15Jz+HzfWyVCIc79Ywnze2JKkc4ra2E2GsRFag\nP0JsOuhAV6ejOsQsxPrIdolPtduvltvtqhw6lZdx5HEdyEyjUpageoqr4NcJY2daGK/U8NnrUg7L\nwJTN4Ix0AVir9HDGlDkrBwt4ytCMpD1pHG0Z3dxKSnYqhwJyCwzOSIbjOC197sbhd0EHbfJSxIfY\na6py2KtHv9ajvsLolv/JA5oBWj77aweU179oq238LesvsmMkcIgz0Iony0jKPcUDjes9BbzkHGaQ\n2oG+6naxQAHmbw/IWYMO6mNwGVgCbokuHvjQw3cPyAa2v3J4CFwrY1Y48MB8U/8BCUwIym/KoWML\nB6NJHTwA8RQSoOLAFEkSX9ig0gMIAIX6e1tEqFsAF2uQwFmSw0USSG/TFIipFEB6AR0K1HyHI4/J\n0gWegy+S2SrhLRpDAGY3UKJAzXdA6oEHUGSLZJHwxBYdCBDF6hmFYBVdsn2AKZIYs2iE77AI3fut\nUTmMA+d6EqAkmSKJT9DySLfIhgB9G6ZIh5pycGzh4AI0UUyRTFgYy/szqf9CfPVjwGGRXpYH1Omt\nhovkRKN+hSaoRqMIwGt8rYrz3Rw2Yf70gDuUZLhIdhyHFq1RpjEEYObt+bkmxV2HdLFEggvwi9al\n5XIcCQQ3TrBIMjuLAXBC3o85ert7JMB+QFy/eN4NI4GRH7HhwB+u8vuFvy0h3AAAAABJRU5ErkJg\ngg==\n",
      "text/latex": [
       "$$\\frac{2 a + 5}{\\left(a + 2\\right) \\left(a + 3\\right)}$$"
      ],
      "text/plain": [
       "    2⋅a + 5    \n",
       "───────────────\n",
       "(a + 2)⋅(a + 3)"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "together(f2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Simplify usually combines fractions but does not factor: "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAIIAAAAvBAMAAADdrw/+AAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAIpm7MhCriUTv3c12\nVGZoascqAAAACXBIWXMAAA7EAAAOxAGVKw4bAAACs0lEQVRIDe2WzWsTQRjGn02y+dpuSCMo9LQk\nYC9KK3pS0OhfsKdCvSQIXrRgiGIugrnWi5YiWAsSPNSDivVqhKQFUU9G/wHr1UPpwdDi1/rOzs42\n231NFkoPgnPYd/eZ3zz77uzMvguEW6F0KiwCxpvEcU4Pa3oVt5thGRnHqTEyIyVtZO4N6GZXXhg3\n1wbUYaeZFpLfBgDlkBzQhp8a/f06kH+2D23y2H15Jz+HzfWyVCIc79Ywnze2JKkc4ra2E2GsRFag\nP0JsOuhAV6ejOsQsxPrIdolPtduvltvtqhw6lZdx5HEdyEyjUpageoqr4NcJY2daGK/U8NnrUg7L\nwJTN4Ix0AVir9HDGlDkrBwt4ytCMpD1pHG0Z3dxKSnYqhwJyCwzOSIbjOC197sbhd0EHbfJSxIfY\na6py2KtHv9ajvsLolv/JA5oBWj77aweU179oq238LesvsmMkcIgz0Iony0jKPcUDjes9BbzkHGaQ\n2oG+6naxQAHmbw/IWYMO6mNwGVgCbokuHvjQw3cPyAa2v3J4CFwrY1Y48MB8U/8BCUwIym/KoWML\nB6NJHTwA8RQSoOLAFEkSX9ig0gMIAIX6e1tEqFsAF2uQwFmSw0USSG/TFIipFEB6AR0K1HyHI4/J\n0gWegy+S2SrhLRpDAGY3UKJAzXdA6oEHUGSLZJHwxBYdCBDF6hmFYBVdsn2AKZIYs2iE77AI3fut\nUTmMA+d6EqAkmSKJT9DySLfIhgB9G6ZIh5pycGzh4AI0UUyRTFgYy/szqf9CfPVjwGGRXpYH1Omt\nhovkRKN+hSaoRqMIwGt8rYrz3Rw2Yf70gDuUZLhIdhyHFq1RpjEEYObt+bkmxV2HdLFEggvwi9al\n5XIcCQQ3TrBIMjuLAXBC3o85ert7JMB+QFy/eN4NI4GRH7HhwB+u8vuFvy0h3AAAAABJRU5ErkJg\ngg==\n",
      "text/latex": [
       "$$\\frac{2 a + 5}{\\left(a + 2\\right) \\left(a + 3\\right)}$$"
      ],
      "text/plain": [
       "    2⋅a + 5    \n",
       "───────────────\n",
       "(a + 2)⋅(a + 3)"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "simplify(f2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Calculus"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In addition to algebraic manipulations, the other main use of CAS is to do calculus, like derivatives and integrals of algebraic expressions."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Differentiation"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Differentiation is usually simple. Use the `diff` function. The first argument is the expression to take the derivative of, and the second argument is the symbol by which to take the derivative:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAEgAAAAbBAMAAAAt2dQtAAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAMmYiu80QdonvRN2ZVKvu110NAAABZElEQVQoFY2Sv0vDQBTHv0na/CBE+w+oWcQ1qJOTKDgJdomDWAiIdBPFQSctguBQpKM4qZPgYDdxEIqzQzcHcXARR0HI4BLf5d21HJamb7j3vt/78O5dckBRNFeTIgRuNFYthPzI+CmEvCvrtxACgnQEyN8dAWoSY4S0DA6zQr7ZoWV+MJC7H7Te4hpYHwKV6aDa+wqchgZtaYo2vSz7hhdp9qum7BbLO82FDqHGu+KC9aOFQ/kxJORkFB1A7FIsAXbDfPCrLCV0NrE/M0fONLtPgJu4aSBHY8joutGe2H9j6JI6obzIAr2ZSvgU1hT7BAHjPNFpHD/G8aZwJtEWSUJ0HNUVJCL3Oz0j//fy7jR4kBzDSXJGHWenyF+RHPwcuO+uYZYZBTltXAjnhW1quHNQPwlZKagU4ks4G2z78u46JJXV4iJ/LtKjdNMvqXL51sCyZutiW8lhj67XwAoV/i+bct4/Xs5GamR386YAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$\\left(x + \\pi\\right)^{2}$$"
      ],
      "text/plain": [
       "       2\n",
       "(x + π) "
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAFgAAAAbBAMAAAAKd1XFAAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAMpndu3bvImbNiRBUq0Qb3U6NAAABoUlEQVQ4EZWRP0jDQBTGv/6JTf+AxVmxODl2UCeHbrpZBxEEsYOTgmQo2EmyOLgV0SEoEkRBhUKWVhSEgjg6OAiidHJx00FEqFjfyyVeLi7xDXff970fd+8SIGodN5yoKOJmvBQdtvW3yDAQr/8DbuWjw83d6CyNUZJ0zJQ6pHR3gNgXxwNurxoigvYOaOVTnxyNuflesBvSaSBh6KuUasvc0mxaZJ1LSUqzETtuGKRqO7Sgj6WsGylJZSu+tV342bdiV2Hse13dcOFDss3FjYWyAms9qgLAXa4mXHiaLrP18URdpN7JZ4Pzm+uUbIkUtoAngYyT6ea80QUca2eMWeauBZzLC3iNTka6JELAnzmJJ46GRX6JXxjoFxOfWtaEZW0zMIQibx582+l83JOlMSjLw+FdnjyKLlv5rdyfQg/MOUvQVDjbxTfD/gOBd7YN4LU9gxprKm9mrYgVtiO8cB31Hmili67mmicmJ1QenDTxyPaAF1kJQ2pS/tcQYaqiNKEXFP+iuExZscBUyAftRdCwroaDgP9zUMoMdFWpe+/5AcqTWrMDyYm/AAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$4 \\left(x + \\pi\\right)^{3}$$"
      ],
      "text/plain": [
       "         3\n",
       "4⋅(x + π) "
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "diff(y**2, x)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For higher order derivatives we can do:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAGEAAAAbBAMAAACekfw3AAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAzRAiu5mrdu/dZjKJRFRer8KoAAAB1UlEQVQ4EZWTP0gjQRTGv2xi1phdTcTGyilELIRLccVpYworqyBqHbXwtDFoIYJwiI1XHCoWlgbEQm20tdCgiIWC6WzFP9h5QRAR/6zvzcwqExJhXzHz3ve9376ZZRcIEk5/X5B26j3CUEBiBQepYMg/dBeDEcB/EZRYDQo4mXJir1z4qrc53ZB1IxAe6NnhPJyWSsUlSh1uwaX15wPQBueN20KClmqRAHbvbwRaB4kYBha4cdbotlJGSeai55FkE/EXmKBxmDda6nNG2e5XTLQISbhLvij3MiJ0qV0mKNYEwO/Omh65OJEKfOKP53mPypWGItxXKiJ5oAObuWWDcE7vuqZSQF1CyfIeQCxNZewSOMS5uFaWnrGPI3uHlPolJWuin6vaIiDQpI3PUyEdFaTFS9qQp7KzXDEBPPECJ5lsnksmM5TGszFWTOIW4ZQ6FeIvsLiBjpFTe02+QVD2+SZ5RjwDmwi++ZVdwqTq9IkfoqFIinHzzrPjMdKcLNz3SClMIIdPzKC2QGVNhkXafz+Po8Xznimnudbo5OyWNL6IXkQLJIV4UHmsGII/Q4u/DFMX6vP3HTfvZ3LXX4KhIULXrxZWopLz3R9V5WldlZ6jtHVtfQDvsmc+fdUw/AAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$12 \\left(x + \\pi\\right)^{2}$$"
      ],
      "text/plain": [
       "          2\n",
       "12⋅(x + π) "
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "diff(y**2, x, x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAGEAAAAbBAMAAACekfw3AAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAzRAiu5mrdu/dZjKJRFRer8KoAAAB1UlEQVQ4EZWTP0gjQRTGv2xi1phdTcTGyilELIRLccVpYworqyBqHbXwtDFoIYJwiI1XHCoWlgbEQm20tdCgiIWC6WzFP9h5QRAR/6zvzcwqExJhXzHz3ve9376ZZRcIEk5/X5B26j3CUEBiBQepYMg/dBeDEcB/EZRYDQo4mXJir1z4qrc53ZB1IxAe6NnhPJyWSsUlSh1uwaX15wPQBueN20KClmqRAHbvbwRaB4kYBha4cdbotlJGSeai55FkE/EXmKBxmDda6nNG2e5XTLQISbhLvij3MiJ0qV0mKNYEwO/Omh65OJEKfOKP53mPypWGItxXKiJ5oAObuWWDcE7vuqZSQF1CyfIeQCxNZewSOMS5uFaWnrGPI3uHlPolJWuin6vaIiDQpI3PUyEdFaTFS9qQp7KzXDEBPPECJ5lsnksmM5TGszFWTOIW4ZQ6FeIvsLiBjpFTe02+QVD2+SZ5RjwDmwi++ZVdwqTq9IkfoqFIinHzzrPjMdKcLNz3SClMIIdPzKC2QGVNhkXafz+Po8Xznimnudbo5OyWNL6IXkQLJIV4UHmsGII/Q4u/DFMX6vP3HTfvZ3LXX4KhIULXrxZWopLz3R9V5WldlZ6jtHVtfQDvsmc+fdUw/AAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$12 \\left(x + \\pi\\right)^{2}$$"
      ],
      "text/plain": [
       "          2\n",
       "12⋅(x + π) "
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "diff(y**2, x, 2) # same as above"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "To calculate the derivative of a multivariate expression, we can do:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [],
   "source": [
    "x, y, z = symbols(\"x,y,z\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "f = sin(x*y) + cos(y*z)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$\\frac{d^3f}{dxdy^2}$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAPgAAAAVBAMAAACZJT5kAAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAEM3dMnarIkSJZlS775nN5rpQAAADo0lEQVRIDc1VTWhUVxT+3sxL5j8+BIVAxXF0IegiVERKuxikdeHCPBcTCaJGUfxZlNkpbSIDxYULySikNl3oYCtiF2XEhQiKg/gDohhF0ZUMQQVBagJp/a3T79x335t596Vx6yEn7zvfOfc79517XwJ8Xrb+E9uxa50Fv3cGc+CQaroIiEcs0YhQYWI4FHYXQyFw8OU1zdgP2ylDdScz4qbFHJMx4iXhOB8OrSGcrHiU/badMlRjzIibNmgSRtxVDRN+vVVWfLeD3ES4QiK/SmdExBSS1COd/79HzmsSpBdplHEVyPWheyZIBsBQtbg/ccOSfQZhhj8ZRKzuEbp5bDponvg2KI2ormBK3DOrtPvQGGGqyT0p3PsMiXsMXozX0Vv6BfbmUp4FJ+gLBg4MutYJFyOOWkAKujlRfBqqePgfrH3y3YBLKqIqKuKe9eI390vCbA3wcPUyuqaAkbr9yF6DrPsFIFO5xf1U06vj+VRmAtv4yeRJ0trNR6uAKr4BrHQTr5mMqJ4iKe7ZUZx0LhDG64DCifoksg2ggMxMvAp75ogDquJrvoeTms6Uf+zJ4zabyo5o7ebfMFLFbH4HeMcwonqe5HnMXyW2DA5WMgZyFXjYwkPMc2F9JNnPHb2Nf9gkBY/55og1WJVz8TcHPCVsR/OeBiNVzOZXITURVfSTFPdNirwyb0FyGv1FJIW+UgE+WMdaTWI2h+wKGHVs3mvVPFUoLL1fKDQlNyC/VDGbczR+805VszmFLK6SAXHGxJzqFqr4b/5xP9JvmOPYuekixzOJrgnAv8j+2DNN7Ad/WNxubqpCvpn2d3OOl2sjGbkaHs4OyWqeOTK5JpJvLgL7GPPCZZxt6HKYZUnkwm0AeDyquN08ohq6cMn32akE+yI1BI17Gkm5KyM1HLcfIFa97OAm45857/pd/AC8xChX9DRJ0vSbJ74af94HqGLOXI89ovoXV4grs3ZtHPxDEKeosbV362sS1veDZRwc34PDp89WGHNYC0sLfq3xMfaqzD/RQtJ081ir1WJzKV7X2r6utfPSv0OzqC7nCnHD1rRjnnrU4mzo2yTBiA78M/dz4aehmpgAxE370yd2YHHFxx3PdFMH3XlLLuCYDpM1DWZ9GKoplwdMNy1b1sxqXDdzKpaDF4u7WS638oSfNkN1PleImxb82z+0tWjmVDys2WTpKVGgOmttQBqq8gL+SwQ1AniP5zT1UQQVZwI0Nwippjld+n+InBDEnxdn1wAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$- x \\left(x y \\cos{\\left (x y \\right )} + 2 \\sin{\\left (x y \\right )}\\right)$$"
      ],
      "text/plain": [
       "-x⋅(x⋅y⋅cos(x⋅y) + 2⋅sin(x⋅y))"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "diff(f, x, 1, y, 2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Integration"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Integration is done in a similar fashion:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAKAAAAAVBAMAAAAz5vjYAAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAMnZUzRC73UTviSKZZqszMyTAAAACz0lEQVQ4EbVUTWgTQRT+tsluNtmkVhE82S6RHqxBc1GpCi4Yq8c9iGAPWooUpChFvfUSeil6aSwVCvUQioLUogGhEFRYpXgQ0VgKQlVIRUH8gUax1FqtbyaZnZ2QHn2X+b7vvffNvJlNgP8e24M7vAqShlgrBeRES5Voo1K0eiQGmmsVQU3FMwpdrDJtVaphV2JCjsIakKOKFlYYJx2qJKheUHXBmvIC8bWOMm1CKcCpGg3Zqi5YVN1Iz/GEtVnkYQ74kINwuso3MhxWy3EE2o6kM/MXW29s2W1TMuYBevLL0CS6n8C6zjnrEYb6s6k0upO3eR/p01Q+baPoYnicPfg0TgIDuAB02dZvKjBI7MZr+zLynWhaQsIhkUIYFtPahDYIw+Z9wHk6QyiHPdB7Uy+obh5XXOSZ4TngDwkRGvEW7rkHrfQsjB6EBpidNMwgVInkoVV4H3AJuB930AcdVpnq9iOyvAvM8CzwnYRoFnDRRYNgFJtsaEskUtROqK8RbqNNV3kfME7lUZu3trK6Nug31z1m2CcNq8j8ibaWqmEskzk2lsl4gMk2PZwFlnkfN8SIq1UoRWlm+ACJlYAhG5kGogPGHeykMnVk/4RrvI+PjFk05YBDzA/DOAB8CxiyR9lLj9EOo8zk+kfJ0PRRD+YK7+OPQmVUG/LQTIbz6HTRz+atjRwrw/xhLFklxHtMeqW4x/b17xDFEu5o1xDO8z7gLuWeYqSEbQtzxwk/x9W5hWzr+sfW9cV9v8p8RP19e8c7epXPKfqOwlnwEJ+N/rWjgIdTn3gfZdiHfXryZQFeYixLmJmqMSgp3SKKNSoMZbaKIgW2zgrZosusi7eCf8CZLDBZoybdbaNI0NU5+opIxWyB/NXgWxK9iF6a2/ETG4B+RGzDFskTAsjV/4MdSrXQL1HYy4I6NAMz+djX+n0kwSMJgTdB0hDT9yAjUcA/yrOz2e5GeOoAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$\\sin{\\left (x y \\right )} + \\cos{\\left (y z \\right )}$$"
      ],
      "text/plain": [
       "sin(x⋅y) + cos(y⋅z)"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "f"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAATYAAABACAMAAACnbqvzAAAAPFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAo1xBWAAAAE3RSTlMAEHarIkSJZt3NVLsyme/X8+f1kl1O4QAACBVJREFUeAHtXImWoygUBQTc0J4Z/v9f5y1srol2aSWV4pyKyibcvI0LKSHeKmm9NtxuLfOH5ulKHZ6ZtKtNXL2a/RMza9/Kw/PqN5pYd7ir92yg/HB84GZLPmV/vLN3bOH8mYn2q5YN599/hrg1fhMBIay1FcCglLKglKqubZCyhiXEqsEpqGFsBRkNKq7akkNu8UM+zZ6wVWD34a8H/ygbwEYIzZ7AtTR9JUXVisYIK7wUbsTMDgH88Wnw275PAxaQnMfPXmk/dJI9gWHFBkFssbmWBsRPUWYowiY/OPV+O9QyhJeoSYqqQZjee0NYmCRSQcVJLkk9gyB+LWRoIl4qtQGItUFpxiRKmwMj2LFRc9GNYBn6AFBUMZIzyIiudWkqtRW6rFUPeZptAj/JAS3qTu07ilq/MwKQMCGV6EER9Sg7DFQYL7B0kLQXFm7Q3DXgFoJssvXD8mVyozQ739OyAedULOP80JKl3fFjW718Zf4ubMIOClEAhzpo0VlwqGG45DRlpQzkoQKhFLFITKY4H+kQpXResPs8ETY2GbaUv93G1xTuw7b5TjV1JBLQRJmEtDufKtnEzZ5XCjAGSqmnLjr2Vin37puTsAVljaMFj2AYr26KZ6wQrqdgS4aUOvEEm9nxZLN3XvJ4FjYzgaerLZs0uSdOrhpHBE6itoO5Mu2oOtsGvZdgEWCKYERnE52sOyQvBY3/3qj6LGyiKzUnTZQMXXpa3FRo21yDQPU47xEiwRg4WtFhpKPYs8CdbSn9+Qcvcd2sPX0/ji9Q63vSadhODZdga8LEAfeW4xnsS3diQD3v515jImzgvV8NNtk2KbUoS/5sQhhWE8Lmgln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zcmrRwjTrAiaXFRpjldGszZPoTS/nQ9H0vZOVWqAOckZyuETYm2Ra84P1neVxPJO/G2GbZjsLTWeapR6IpV6gD7Cw6jv2OS5ry1rM8bKBlE5c0+8PE0i/cUk5ed/HWOi0mFkVlRgHbrWd5ZPDy8y2XcmwvfF/AxjO46SwPm2XQieel7ZVQLGC78yxPF1dAB2DT7rldpTvgzbDdcZYn8oZ15ZuqQgKnrzSQjMw766G2lU4HkerGNx18QPhZ+bHWPX2viXEMte8AafmODNsNh1ISb5h3SHs64Uru3OARTaLGwkEkibwG78qQf0PJTIxjrr2c1PU5t8KWeMMCNorJifdjQgajjHgQCSNSMaL1I64GYUuMY659PUjLN2TYrj/Lk5gcACHux/OJXxQr54caEvIU8SBSB1LY4YE3Q+EK2cHAOBa1l5O6PifDJi4/y1Pwhhk2omURtjoT9OloCIiUFbA1wMQgwRYYx6L29SAt31DAdvlZniRtELOhtAFW4RQgSxs+U0qwDQ2c77d9+PEqwhYZR4dNvi8VsF1/lifxhqyHKEN8eJIw4J0nwCmf33IePCsgxKE7wpYYx1z7O8ArYBNfcZZndw6JNwSOEAjSGWyOHMMA7jQaPrhDpxB38hDixDjm2ruvvKiwhA2jqucO3JwdTOQNoX1VIf8KZ5Aq1/We3CXRi3JyEIl+/8A/gqC60iTGMdQ+O5S/a1fC9nc9fVTrX9hOfd2/sJ2CrcrR0qn2H9ro1P9l+FCsimlLP9uoKcp+b7cRsN8bbm8P7MVLfp3CqS9I7v1c/lSPH9JInTzm9iHwbE5z/Z+KbVZ/qYL/AaC6PSjT0ydtAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$x \\cos{\\left (y z \\right )} + \\begin{cases} - \\frac{\\cos{\\left (x y \\right )}}{y} & \\text{for}\\: y \\neq 0 \\\\0 & \\text{otherwise} \\end{cases}$$"
      ],
      "text/plain": [
       "             ⎛⎧-cos(x⋅y)            ⎞\n",
       "             ⎜⎪──────────  for y ≠ 0⎟\n",
       "x⋅cos(y⋅z) + ⎜⎨    y                ⎟\n",
       "             ⎜⎪                     ⎟\n",
       "             ⎝⎩    0       otherwise⎠"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "integrate(f, x)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "By providing limits for the integration variable we can evaluate definite integrals:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAFAAAAAUBAMAAADo9qfkAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAIpm7MhCriUTv3c12\nVGZoascqAAAACXBIWXMAAA7EAAAOxAGVKw4bAAABuElEQVQoFXWTP2hTURTGf695r3lNkxgUh2Z6\ntEMHHVIKTqUEurkkINihQlNBLBU0Zqngkk0MDgotpNWh3bqoFToUOjRmKYKF4CBEBLN1aIb+kxYR\n43dNW/NK8sE57/u+c7jv3Hfvgw6wai2FaAys/uFki3VOr5wzQ6bgNsETn3cqPvjMCbgHCz6vKaKe\nzwyWWIRHSZ/5T4Q0VQucl2ym2zbGW7oMXTfpfRqcwVyF8c9PsLfrq/LKijvXseYpFO0a9Eu7x0p9\nFfuVvUygdAuWpEcV2SrhPWekPCC+qwhllDaIHIWy2EfP05Sk3+rDVa4RSDhYCelvCrOqc6CUqsBx\n6PCjKEV5vOFSCcY0GSkIe3q6v5V+5OHQedowhhpxf5JK4mZETeMXrNj/FQ+uEjUHoFfTtcon+Gr6\nKGB7hGNmRiI9Hu7Jd3iogtlMIMMNIh7d4rvEZ3MzIn01Httz9GaraYakc4quhPuHmzv1FfFBNhuN\nXyLO3a0Yl2eneVbfyUsXjHe/vI8XfW30mqItmkeoKZuwltp2yTSX4gGT+dO6LkUnaNB3jJxVdc06\nQRf3RTl5VjX764CLv8JfPcJj8HGPsdwAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$2 \\cos{\\left (y z \\right )}$$"
      ],
      "text/plain": [
       "2⋅cos(y⋅z)"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "integrate(f, (x, -1, 1))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "and also improper integrals"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAB0AAAAVBAMAAABI7vhRAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAInarRM2ZVBDdiWbv\nuzJCz3LGAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAAr0lEQVQYGWNggADG/2DwAcplYHaAsSC0KCqX\nIR2VzzEBlc9WgMrvROUyrEblg7TrAx3wDSrMtIGBa12RtKIAkO8CxJwMDM8ZFjI9ADKZjgIJJSBm\nuMDcACQl9B0YGEC28xkAVQFB/wUG7gVAmm0DfwOQYmD7yMAJYvQ38DsAKQbGbwy7QLQmA88CEM1g\n3zADRN1mYF4AohneL08A0zCC9WgDjAmm2WGuhIkGwhhAGgDwdic2xV4k0wAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$\\sqrt{\\pi}$$"
      ],
      "text/plain": [
       "  ___\n",
       "╲╱ π "
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "integrate(exp(-x**2), (x, -oo, oo))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Remember, `oo` is the SymPy notation for inifinity."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Sums and products"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can evaluate sums and products using the functions: 'Sum'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [],
   "source": [
    "n = Symbol(\"n\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAADsAAAA9BAMAAADhUgydAAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAMruZq91U7yJ2iWYQRM2bSrnQAAACDklEQVQ4Ec2VO0gcQRjH/8ednne7eyexsvHAyspXUiWCNiKH4KPSgHqr+CgvKRMidyQQCETu4DQBqyuTJllQDKRa0thY2EggjdeKonfgG3Uy+5idzT6mzlfs/r//j+9jZ2ZnBjDiEZD4WjVlwKNtGPiJxQBiWUvAJNJ6GF+CfI24Go4jd2jSxLgswLS5AMsNpPfDqzEr+PIVoOIZ9wlv9S6XRfLpADeAt3fuzKt/PRFiJP4HfEZ43DgjcD4tT1pNc29tu3DlxzEywUwppzLpVCN3zjxEa0xynCEaM9HHFMcSuWYmEraKjlyMMrPngqnA9y7pDfRtUyGXIozvV7qIp0hNhOXCrQgjT/ZFPEreiDByru5pvoJ1u6g0I6z+XBRhpeGnyf4BZmZUpvj7C8bsRH7FXUdNI1O0ktSQY3KxipI9Gd3cdKu8bmZJPqpmN35uJT+KjrnjKCBp/QWuUSkvXHjL0iWVefKgWfCn68N6GUpVaaVAfs3o+3FrR/R2lukx17G8oFOSejg1Y4quhPlPRtQ5tDRQIMSoG+QLRMw9Jsv3kOoGCo7mOmK1YGS4dCulNT2Ux6vI69VQTOf6m2QMyhv0VqBxQI+1T15Ec+NWEAW9FUThx9Kz9opTEYAPtXgxZkzrMeDHHzdcB7kfI4vfguZ4iccRs/lRUPOWOmbnWTm9FTyhDGFTsz3jVvg3/gK+T7KE+MaJIAAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$\\sum_{n=1}^{10} \\frac{1}{n^{2}}$$"
      ],
      "text/plain": [
       "  10    \n",
       " ____   \n",
       " ╲      \n",
       "  ╲   1 \n",
       "   ╲  ──\n",
       "   ╱   2\n",
       "  ╱   n \n",
       " ╱      \n",
       " ‾‾‾‾   \n",
       "n = 1   "
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Sum(1/n**2, (n, 1, 10))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAJ8AAAAPBAMAAAAIUwCQAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAVO8Qq5l2zWbdMoki\nu0RRNjIpAAAACXBIWXMAAA7EAAAOxAGVKw4bAAACUElEQVQ4Ea2TP2gTUQDGf+k1TZo/7eHoYvwD\nXaqeRShODaVB0aEVmqn+CYoUVEiGDuJicNAOgg6Kk5jVyQ5FxCAJgpMOtzg4NSg4C61WQRu/995d\nrt09wpfL+77fl/fevYPoylzNnddtbgFvab3Li0q7vQbtG63c46V22wqF9ls/zttv2TZDQkPqsPWG\n+n0VMBoy1SxM8rDf75eZ7qUbWd1tWeE9qV8xsC/A2k4SmpOLm7Yws37TfF8JmYUKF2AYPlEM010o\nW6Hu89sBXmVehcZ2ktAw4gqF6yrcD9mGDprtG8b+aCivT8sKX3qeTAfUA2fbjPnziI79aCifCb2/\nUG/BWI1iycTg20DMkgeF1nYZVyhayXiGq9da8EBDE5phD4owfvvVJSUwMSenNPNBobVdZnhAxz7F\noLCDV1NhB+404TXM3GLI14r1y8mHJ0EMaMnWdpmEjn0hfNZ+qTBTS3V8vO8q3CStMzBjTCvkj8WA\nKTR2lBnQsW+Yy939ppB71zstRhpa8iOyO7BsTCtwKNi1ZGNHmYSO9/C0du7rmi0EnQkdSEYbZPUU\nnplCIx9hw08Kre0yu+nooUzoP07Mzc0fqYlc0RLLOoklM0NvSyNW+sGeQmu7zG46KlyApwKHQu52\nczp/LzWQ0yaVyP3QuJWj8LybzNDaLpPQbg9nGnqtspMCx0OWg+kmHFCGc0z5pEyhlVVSP+NN10Nx\nts0kNOnZ7TOMliksVRTJb2w181Vz+N75knz1rN6eg7qzMla92HMAi8dXms52mQGt7P+9/gFEfua1\nt0ciqgAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$1.54976773116654$$"
      ],
      "text/plain": [
       "1.54976773116654"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Sum(1/n**2, (n,1, 10)).evalf()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAJ8AAAAPBAMAAAAIUwCQAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAVO8Qq5l2zWbdiTJE\nuyIU2bFIAAAACXBIWXMAAA7EAAAOxAGVKw4bAAACpklEQVQ4Ea1TQWsTQRh9223TdLPZ5FBPHmqt\nIEIrS62V9tJQo1Q8ZNEGoShEoQp6aKQeDV0U1JPVgwiCGMRKrZTsQS9ejIIHT1bP1u5FUA9KGmna\nYhvffNMUf4ALeftm3puXmfm+BRqP9fQ5aczTYI49CYEfcx+V/BI4OKtU8Qj0Xzy9pQhzsosBnLn5\nJCeNLqXAvIpTfLUtaOj1nf1wPHT4HD8ELmMg1B5t9NCsFlMR1gfrD77CWAX6RqsUgLiHRb7OqUDC\nMHAEkQoSd4BID6K7YOW1R4yGDycvimaHgd2YSGKNqyM68ENIDucmAxXUgBLsbgxx2bcC4ikYVYhH\nwFqAyb+iotk+IBO8LZtc1gj8pPJgtTKQYG4AEwEn1JGLBSRSsCsQj4C94Vpa0WzKZSCvj0duBNZe\njZeB2ypQwV7ukGPzARANCxjyYK9APNqYWZ3VCoQx55ELDBRJ9JHNmo9OmDlmCZSAKd7Ts5NAPwr4\nVURsXTzaCKs+qRXNAHudTXGPoY3AuosTrgUGCrTmjFKS6uMyiirQU4HKc0CMaH+/rBXN2B4puq3u\n7UBVn+nyThUogBuXSgHVpi4jYKA+sngEoilMaEUYjVn+WGpucavK9xl4vchAU4ESM64TIl4ZBANZ\nFKMC5fEFmkLEtCKMKR7wE1hKbgey8abfpNOZPWcV5Bh4BYkqA9vT6eWj8QVEq6o5p8sCQ9RHRBEG\n7IAT8jL+CXzN+6GrSW2OcC2Mbap32ybH0tgteYhHgPvCF1E04xcbCXtYas6rI7N9m4tmJx0JFUi4\n4B7yEfXRkeOYTXkXvYH2iNGeRFQrmn2fmzmGWzBWgJbh2oiUaGY0YJmWfvsCVlZ9/O+yn4nz9REM\nnj9OJh6BF2NKV4qwqXp9DXb2TJmT//n5CzSjDuDy+pXbAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$1.64493406684823$$"
      ],
      "text/plain": [
       "1.64493406684823"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Sum(1/n**2, (n, 1, oo)).evalf()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Products work much the same way:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAC8AAAA9BAMAAADPFy0PAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAMs2Zq91U7yJ2iWZE\nELuNX9C8AAAACXBIWXMAAA7EAAAOxAGVKw4bAAABXElEQVQ4EWNgAAEhBgbOlQvATBRC2JWBYRdD\nCooYhJPKwBDDwH8BUyaVgfcjA3sCNgnGHwysG7BK/GVgnYBV4gcDO1YJoB38B7DpwOGqdAaGydj8\n0RzvycBlZYtp0iAUYf+PAB+R3cdx5P+/DhDY/19NAFmCgeH9FzA///8FVHGG9VCJr2jiQ1zilEfn\nFEiCQfOgwbsJvD/AfkWVYEwIYuCAhCaqBC/vHwbuD1h0MLB9YGBRwCbBrMDAvwEc0KhGMbAvYMi/\nsACkBU2i/wDDIm4BLBJHGRhatoHE0XWAxQZe4j0k3axHS1ccwv//v2lg4JX6/1+tAeFUBgZw2v3A\nwAdKwShpF1kRPdjAkg4rAJV02AGwpMMOkCW4rSUnw1WhSJzfwN7AogQE2gwMyBK9U5GKT2QJBk+G\n41iNYihkMGYEG6WJahTHB4aYRJgWYEkHBzwODLM2QHmgkg4GAOSmp5CzUioBAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$\\prod_{n=1}^{10} n$$"
      ],
      "text/plain": [
       "  10   \n",
       "┬───┬  \n",
       "│   │ n\n",
       "│   │  \n",
       "n = 1  "
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Product(n, (n, 1, 10)) # 10!"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Limits"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Limits can be evaluated using the `limit` function. For example, "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAAgAAAAPBAMAAAArJJMAAAAAJFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADHJj5lAAAAC3RSTlMAzRAiu5mrdu/dZmiL4QAAAAAjSURBVAgdY2BgEGJgYDDZxMCgEgYkGNhJJVgzdmYB9TEwAACPpQrvlUCHcAAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$1$$"
      ],
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "limit(sin(x)/x, x, 0)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can use 'limit' to check the result of derivation using the `diff` function:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAKAAAAAUBAMAAAD4uit9AAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAMnZUZs0Qu91E7yKJ\nmaurDqYVAAAACXBIWXMAAA7EAAAOxAGVKw4bAAACz0lEQVQ4EXVVX0hTURz+rtvu3bybWRD1pBcD\nH6rV6KHCoIYUBCqsh1ERxCWIIKRECqFBDCoifBk+SQSaYCARDJIMIRiDgihpBeKL0YoKwgKtSFaa\nfffsnvtnzQN35/t9v+/3nfu75547oHZMeokub1AX60kPHcxXA2XMJfU+FwNNtsLL+fGUL1yoRsqK\ny4Z8FmrKzdRHp3z0WV8kgh4/VbTDgOHnZRQsSSTmqOELrWDQz5y3w/UMw76GoI4Kvb7RcdGzDhQg\nlKvG6xk+9stxEsq2ztTUX2x+sGmXwWQDW1DbFoaKOPMG+j3E7JakoTo/k0Bv23NRR32c8riBaRPD\nE0oSeItzQBangZuG/ocCjWQvjho3UOhAwyKCKZIc0nA6odxXBqEZog64BEQDo9gNtT8+R90R3DZh\n4CpwBfhJIpwAnuGVeUBPzELrQyBLkkMaphFYChegLIk64BrwMJbCAFSIF24/wss7YBleBr6zsDEH\nmDjORjCGDQaURZLRdPrEeDpdJrvKsJWLrog6YILyRkOUbjGtHNSnayXLcMA1rKLIL7Q2Vw0ptO8w\nYi16iIsuizphiBFTWQIiZaZo+AjBisfQapkN8YeNbKcsS8hhGzp3uCrqRMuYRcMocFDohrEH+Ogx\ntDZlLzejHVrZoms3JU3vxhIiFVEnNoUyagMlNMHalA4TGatfu+UoxT+0RR75WF+EuxQrUMUhN2U6\niRfKXYQKog6YYW4OI0ls7e68RTyPO53duZa1zy1r7/f9LosW1Q/t8cN8/l/jfI9CzVRxSEP12848\nnrz8IurID/O6UHyXRyk4zkeLY7z8w3P0+BQhT4I09Iv5muUtZlbStQeNfI/MfcJFLlm0Q1UUypw7\n8+PQlFIrkogaEjmzJiuvo599p5zEOiCDcFIzZLLO58v5wA7Fm3kSpb2s+G+eQqTttcNmHOSCSRcC\nXd6gLq79C/gHf4qzfkFAyyAAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$\\sin{\\left (x y \\right )} + \\cos{\\left (y z \\right )}$$"
      ],
      "text/plain": [
       "sin(x⋅y) + cos(y⋅z)"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "f"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAFMAAAAUBAMAAAADwRznAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAEHaZIu+JVM27RDKr\nZt2dj8xZAAAACXBIWXMAAA7EAAAOxAGVKw4bAAABlUlEQVQoFXWTPUvDUBSG31jbfDUxFBQEh9BK\nXYRmEkXEiBRRUDo46RJaEXEKgrMZHDo6uAiKXXS0/gMFN0EIRZyLCK5qQWg76IlJ9V6jBxLOc86T\n+8G9Af6Lfp/t3LPwO1/kCmmbQx72ORQ8DjnQLA5R5pEl3WYJGOSRpRUWKJdqEHImigYgTFRcDGW3\noY41PGrl6MmML+XNSEhYSIklFKhcdNVV9QmyOQw0iU/oa0d71L1I0DwsJDwcUasKsas7ULtnBkzi\nZyBlpF5FOxLEJoykiTcaoUXtKxd419ujlGKNapAO0BPUF6BuqF1AIR17NaAtbH1YoQoMmJSFQqBO\noq/EjNqag9YhgRZA01zSKxSUJnAM+ZoKVUBMWlA6O8AdMW1LNAroMyKBtoUp1H1qFX1sqOuQnF0D\nh8QVmtk9xXJPSDjASHnWppZwk7cxv3mL88ZDjfiCOtnMDI0SClKwFlrMH8EebCDQ6aU9IdhFLL6v\nSyTQddF92Yx5QSFYcBChEFxCJTv9VYm9elc7FGQ7JvwUYj/MJ3CTXM0O35peAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$y \\cos{\\left (x y \\right )}$$"
      ],
      "text/plain": [
       "y⋅cos(x⋅y)"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "diff(f, x)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$\\displaystyle \\frac{\\mathrm{d}f(x,y)}{\\mathrm{d}x} = \\frac{f(x+h,y)-f(x,y)}{h}$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [],
   "source": [
    "h = Symbol(\"h\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAFMAAAAUBAMAAAADwRznAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAEHaZIu+JVM27RDKr\nZt2dj8xZAAAACXBIWXMAAA7EAAAOxAGVKw4bAAABlUlEQVQoFXWTPUvDUBSG31jbfDUxFBQEh9BK\nXYRmEkXEiBRRUDo46RJaEXEKgrMZHDo6uAiKXXS0/gMFN0EIRZyLCK5qQWg76IlJ9V6jBxLOc86T\n+8G9Af6Lfp/t3LPwO1/kCmmbQx72ORQ8DjnQLA5R5pEl3WYJGOSRpRUWKJdqEHImigYgTFRcDGW3\noY41PGrl6MmML+XNSEhYSIklFKhcdNVV9QmyOQw0iU/oa0d71L1I0DwsJDwcUasKsas7ULtnBkzi\nZyBlpF5FOxLEJoykiTcaoUXtKxd419ujlGKNapAO0BPUF6BuqF1AIR17NaAtbH1YoQoMmJSFQqBO\noq/EjNqag9YhgRZA01zSKxSUJnAM+ZoKVUBMWlA6O8AdMW1LNAroMyKBtoUp1H1qFX1sqOuQnF0D\nh8QVmtk9xXJPSDjASHnWppZwk7cxv3mL88ZDjfiCOtnMDI0SClKwFlrMH8EebCDQ6aU9IdhFLL6v\nSyTQddF92Yx5QSFYcBChEFxCJTv9VYm9elc7FGQ7JvwUYj/MJ3CTXM0O35peAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$y \\cos{\\left (x y \\right )}$$"
      ],
      "text/plain": [
       "y⋅cos(x⋅y)"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "limit((f.subs(x, x+h) - f)/h, h, 0)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "OK!"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can change the direction from which we approach the limiting point using the `dir` keywork argument:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAABMAAAALBAMAAABv+6sJAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAEKvvZom7mXYyzVQi\n3UQ6SGZXAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAAaklEQVQIHWNgYBBgAAIQwaj82YGBIayogYGB\nbQLHLwapDQxTGRg8GRj2J6xkYGA5wACUYP0LJBgcQEyGfBDRAGYm/wNqd2BwZGDgiDE+wMBxgIGd\ngSGcYb4dgytQolxtAwNjvXEAUDncNgBJUBUwaYAbUgAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$\\infty$$"
      ],
      "text/plain": [
       "∞"
      ]
     },
     "execution_count": 69,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "limit(1/x, x, 0, dir=\"+\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAACMAAAALBAMAAAAHCCkxAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAEM3dMqvvZom7mXZU\nIkRJD0iWAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAAfklEQVQIHWNggAMBEAtMQIUYw74VMDB0Lt0A\nV8LA6cD9iUHoAIMHQqiEgeH8BBUGBvYLDELGIKDCANTA8RmkC6gdCkC8+SAChCEAxJr2j4GBsQAm\nwlDIwMDdm3aBgfsCXIiLgaGLwT+PoQIuwsC4KvIAA+P6tAaEENThAgwMAMSLGqu/gFQwAAAAAElF\nTkSuQmCC\n",
      "text/latex": [
       "$$-\\infty$$"
      ],
      "text/plain": [
       "-∞"
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "limit(1/x, x, 0, dir=\"-\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Series"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Series expansion is also one of the most useful features of a CAS. In SymPy we can perform a series expansion of an expression using the `series` function:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAVoAAAAwBAMAAACiZ6/NAAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RS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ea7W4phwI7davaXcFlp+E9sfm0L8uCrU/QyyiCYm54QVC/LSOlLHNdIj4Wotju9+rttcsXjLy8Ui4tjkyYBzxeLbxeJNMhI+sEhIJcThETktUEwL89YxERW51as1MrcQ1Fsqg4IVbizi5zY8H0c8Iqd6ij0itz1yO7hug0ouj5vZ2AlavcV68ndCB5425tYWL8/yLgY95XC1Rt0T9HprE9zC4SZsv0EmQdxf9UoO77/JZy89LzF1pvR6azPc5p+Zf9w1JHKpV2uh70HEmdLd3jP6sCsijzoCizNNHwpUPMJPCgoQ2AIQH3ugCdb4lM8MKbqc44rq/o1NamO7qg3c7vdBxJrwdpOBwB3L2vdQX0URTioNH5Fl3w7IXYVYzTqhYG0tFWr73MB/o1IE/2+PA70VfxTq3CafOqEQDjxC6pV2wC37ngI4Bh8AnDPgIPBz0BW998PDqFHvrHdfMSZlxFPSbB5hiHi1F7ehVwFebD4Y9aEff3AtJPtuaBQ5iK1xbhMVkugR6ozbbQ66xf87rIQdhaSsPn2YqeujdftpTAnRClsb3kXcDiIhU2Lc4tz37vwD3eqXTrvAnB7YpQ/W76/UyTmDt4J8gzZBJPRTH3ncB5J9JX4FPyzQoq5YVk/8HnOBqMhJGhxcg+RREkJCnXebLq/rllTdWDB0c9YohVnIiOLZaEjINnm3o2BhbiN3giG58cA0M7W3DzLi4W40JOwE1m1qAgD37Vn9ZBsS/zqQHYG7SXKiQudWED7ft++v/QZL7ts5iJdwq3zsGHA3AvgEfYnUyeK+rRCIRzCfDrLsy49AqnQY4BGCef2h+DuLe2dpmYdggDidivC7SRK5vXdx/jlI16zXTbgLkRi+lTBuc2MHiAU8wtctr8QLpsiyb1urdQmsxnQziP/fev8A5mex3B66Xa0AAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$1 + x + \\frac{x^{2}}{2} + \\frac{x^{3}}{6} + \\frac{x^{4}}{24} + \\frac{x^{5}}{120} + O\\left(x^{6}\\right)$$"
      ],
      "text/plain": [
       "         2    3    4     5        \n",
       "        x    x    x     x     ⎛ 6⎞\n",
       "1 + x + ── + ── + ── + ─── + O⎝x ⎠\n",
       "        2    6    24   120        "
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "series(exp(x), x)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "By default it expands the expression around $x=0$, but we can expand around any value of $x$ by explicitly include a value in the function call:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAvwAAAAoBAMAAABwRjOsAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAEIl2mSJE3e9UMqtm\nzbsXyEShAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAJmElEQVRoBe1aXYwkVRU+1T3dM93z1/wYNtls\naJklEhJiLzsmJrDSLmM0LOLEB1GyYTpxkzUmOpvg+POwMhj/EAxNgKg8uB3ezQzBDRvRbKO7cR/E\nHUOERBy3X0xIRHZZQYLrZDw/t6pu3bq35lZ1v5hwH26dc+75zvnu6Tu3qm4NwPstZwX+kNPf4R6s\nOwZymK/e/4kc3qFrMRSiCwMpczA3vxgyGOJa3hgCrEO/oiuF5OoKfDY/sBgK8xQGMseji5VmfrIp\nxJcaKVMxQ3no5f/5bnCXT+7SPR/X3LxR889qKBR9gYQaUKe3ysNwbU83ZMn1Xx3u28eDH9nturU0\n5wDrTgB/Tar5tVO/u91rLdwIv9GC+6Luhns0FIq+QHStvZWEAkw+uv9F0+bUq9tXHGOTHmv2lcqq\nA50wL3nVLgFJKi6OSS+AFVhbjG2+qINwPgaR5AtE16tT5Z/1qFuUrvq0qzT6RCL3pFBeD1pJi13z\n+SXtSGW9nDkaD34dljqx5osCc/X7A2FfuvzNmMGOUrXjcnnNNRDbJ7qxnCXVUxyzvC1j3wEoW8wW\n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vDSQWKnHsijF2UiKBHog\nYvw/AGT97vC9MEKawsw6W5zEk/Ux0YZ+IiqEMeCpXmiE5fcEsNvreZwjX8lVmh5EFn+Bys94fIFa\n7vrj0p5Tq2lbYYtswYXhBHywkRu+9cx8JzeIAJjrbOHyE/4qPK5fbhXKrUABPqqPrD06dKRqjn99\nUsmCrT48XCQx5gpaQ5S/ermCbNeaRXJHmAORNLRQXh06hOvmnRE42G7Ap/L/zeAHxnUoqVPOjPC2\nIX4ZRnwFV/+Q5Z/o2RIUsk30C8F00IKueMrv4j8MdDx9dTfM9fQw5V+AYOjNB+ITLJ1aIXn4PyT6\n7Ja7Hcfy93Oj6BNf0Byi/MQVb70nhrr1Arycn7kdUfme3Z7D+iRUFnO4i+upYqsfc33hhRdOP1Lg\n1smbD3HF943zRfY9bY7X9TRlGPG6IdcBfhNoQzl/+ddw78/PW+WaGOSH8gEj48+BeuEuEERBKhkH\nPrmivpHL2+Z87w17n7fZs22TzaDAk4/KNTvIDm4dpdXP+PGu+V/TVv9M432Zo96DQcfb1eV4YXsb\n76O5295DvdwYkFyli1f6ubF8vsv4YO62AqlzJ3wf8P9Rgf8BNeLlKiPUeWYAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$e + e \\left(x - 1\\right) + \\frac{e}{2} \\left(x - 1\\right)^{2} + \\frac{e}{6} \\left(x - 1\\right)^{3} + \\frac{e}{24} \\left(x - 1\\right)^{4} + \\frac{e}{120} \\left(x - 1\\right)^{5} + \\mathcal{O}\\left(\\left(x - 1\\right)^{6}; x\\rightarrow1\\right)$$"
      ],
      "text/plain": [
       "                         2            3            4            5             \n",
       "                ℯ⋅(x - 1)    ℯ⋅(x - 1)    ℯ⋅(x - 1)    ℯ⋅(x - 1)     ⎛       6\n",
       "ℯ + ℯ⋅(x - 1) + ────────── + ────────── + ────────── + ────────── + O⎝(x - 1) \n",
       "                    2            6            24          120                 \n",
       "\n",
       "        \n",
       "       ⎞\n",
       "; x → 1⎠\n",
       "        "
      ]
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "series(exp(x), x, 1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "And we can explicitly define to which order the series expansion should be carried out:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAABUUAAAAoBAMAAAArnobcAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAEIl2mSJE3e9UMqtm\nzbsXyEShAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAQSUlEQVR4Ae1dfYxcVRU/b3bnc2d3hxalpiE7\nbmskCjLdLglasMOyglKElSCgIXQSCPUvuwHrR2rpghFFQLcRI0K0E+Q/YnYRiEghHZHG/gGyxAgR\n2DImgN/QYvkoLYznnHvfu+/d9+6bd9/MX6Y35L577zu/3/mdc+++7ykAx8vxDPQ3A0/2j251H6hW\nrP9MCpZ0KHSUGkginTWTMynEKkhP3gVNHyiYqF88TNZzYlSKqDWwFOz30sv1zpXbBpfYS0iHQj+p\ngaxxy0y2ai9WIXrzzjx9oOgrjwiu18SoFHHrKxVtoJfuhl7AjL1i3rkgCUnmonN8ZolRk/f7UNhM\nCiRUmyp/yd4CJzb9A3Ht0iNXtvT9Nt4Bxs/S8di3o4DMrhOi59uSh5Q8PhlNBWCVGC+oO8a9ZrDh\n/CDYj+qV8PA4MRG1Rx8bbukjtv2Hf3+WKfIA1UfgMV8/KepCuMiHwmZSIJoWDwWhAEO3rf+dPmbs\n5zpHQ/ssvAMMN64IEVgFQOihTuf9CBZrHuQoN512JJVlYlyOgcWButsObocWg/2IXmnTLJSrxe6G\n+AcUmscIvtih8ERGm2+DhRm1JylqCp5WIGolBaLpilBso0lS4vrL3VVxm97WwjvABljpAVXDigJX\nz7XX/lWBfS1LHkSO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klJhfoLN47iPwyGTw6RpbwIG2/kKj2flxL1eYY31ENjYKkH\nsIAO1FNQ7MA12rLHoS8HnzK27ZHiO1bSincru+n8ZltuIMAkfg2I9/UpLrgeA3y2Sr53cQDpVKwA\nXKMsIDsDI6gC9aQMiAnwNwzlY8xSmMHvPrlKyRdI558CvR47V8z0SABwB2C4tuXhdMdR9PWlPXv2\n3lqz9Se/tSat+FzW924tMZGDqwqKdfjiSBvK+IzAttwOcHGFfH+IA0in4u49e955gAWMHqI1Snro\nQXOKgJhgaI6Oo8RCVzKPcpWSL5CPk5qBbk8d23+4IsJZqQ4D9mt0Aa9HI8i6DElfhXYXu6jd9OyJ\n8ftBvuKKsjKPlfA8TS8izyjPQZqHIXWAHfR4nF6vYQApVQDwM/zBJaTIv8l6UlIxQQmvR+eYBQ+h\n8ApXKfkwLFWy8k2eGknfGmmlx0rk5eNrf2NPMlR1brFHSV+jbXson+sZn5/Hf/3EvhRxjWavG980\niz8bWtW0x18K5e+C9I0BpFQB8D6wgHILdteEnnRUTAC/hlXzzJJ7Bso1rtJL8yXly752j80P9ohH\n+EudDt4AWZe1m5rWGOkr8/rRljWWv5hjrc6aDSlc0w8TYRhf2s/i/zXiEWv3uL6nHqyA8E0BpFQB\nn+g8KgRcM/2q1JOSigggM/2IZLlv6jwArlLypcjJccjxDPz/ZOB/nQjAqqJ2ecoAAAAASUVORK5C\nYII=\n",
      "text/latex": [
       "$$e + e \\left(x - 1\\right) + \\frac{e}{2} \\left(x - 1\\right)^{2} + \\frac{e}{6} \\left(x - 1\\right)^{3} + \\frac{e}{24} \\left(x - 1\\right)^{4} + \\frac{e}{120} \\left(x - 1\\right)^{5} + \\frac{e}{720} \\left(x - 1\\right)^{6} + \\frac{e}{5040} \\left(x - 1\\right)^{7} + \\frac{e}{40320} \\left(x - 1\\right)^{8} + \\frac{e}{362880} \\left(x - 1\\right)^{9} + \\mathcal{O}\\left(\\left(x - 1\\right)^{10}; x\\rightarrow1\\right)$$"
      ],
      "text/plain": [
       "                         2            3            4            5            6\n",
       "                ℯ⋅(x - 1)    ℯ⋅(x - 1)    ℯ⋅(x - 1)    ℯ⋅(x - 1)    ℯ⋅(x - 1) \n",
       "ℯ + ℯ⋅(x - 1) + ────────── + ────────── + ────────── + ────────── + ──────────\n",
       "                    2            6            24          120          720    \n",
       "\n",
       "            7            8            9                      \n",
       "   ℯ⋅(x - 1)    ℯ⋅(x - 1)    ℯ⋅(x - 1)     ⎛       10       ⎞\n",
       " + ────────── + ────────── + ────────── + O⎝(x - 1)  ; x → 1⎠\n",
       "      5040        40320        362880                        "
      ]
     },
     "execution_count": 73,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "series(exp(x), x, 1, 10)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The series expansion includes the order of the approximation, which is very useful for keeping track of the order of validity when we do calculations with series expansions of different order:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAMQAAAAwBAMAAAC8i8hXAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAVO8Qq5l2zWbdMiJE\nibtHdKBDAAAACXBIWXMAAA7EAAAOxAGVKw4bAAADm0lEQVRYCcVW30sUURQ+2+zu7M7O6IbYg0JZ\n1kMQNJT4EpKUWOaDC7YRQTZk+hYJBUsQOQ9FhVBQpPQDWnrpLbc3g9B9yB56yIWwiJCG/oBU3BL7\nwXbu3Lkzs7v3JosDHfDe73zfveebmftjBRCFNtAvksASKjUJn+GIaHxoRaTUxj+CyZxgRkdAFo9h\nJi+wGAzIAmCbzrdQGgKzGOc7gCYFZaGlBBZjgVlcFzhIRlAWakHNck1C6fR3k6vUSj7bvFWw3JDY\n8FpIw71vPsDeUqnqqagCt4vJKqk2ogNuGRPcKWKFO1xMvocvejNXFivc4WJSh6sCUaxwJijHpkwO\n7VA/hJJYqZqilopVnEsoP11YAcSKN1DJU6w24Y40PN6PGqJLMOgnXCxW3CEAzx2s5hG89gkeVJfr\nlhKml3tIrHhjAC46iXpiSAfN9EsMS92DQzdZUtaLFYDZ/Z9W82R0xCAtRiIfswDu2TiIJpp69/bM\nb1JpxrsTlF8AQ0iFWoOw6FZbIbpKKs2zcmFdQs8ZgLbj6184W9isqp4pkc59eQD7xtnOBm3Kkbss\nbgJEg7CY0wew8ih+I8Utp+nkFydiBWRxH5JosYh/sRZsaCycxj7aEoyFSs/qVywZGcGm/dyr8wb2\nGCq+VRAfKkK/zi4sWWcBSIXYeJxYYZD7IAiLuiW7Gtm0cicArsJKKEcoPB1IUgvp8gOMiSyS9SU3\nyMyPmczdTOYSIrEi229RRx48nsK3ANlCaEdimVkwhtuzrVktOkrYXgv7v0fyFvgwBmlJeG9Bc0G7\nroVGrm3pCplOLSazBJMgJzyItZBKJsB0npQMW3hh6BcgqpMsuB0Fd4rNs712SXIO5pKLMGVn9jmJ\nHFo96mTCbt0PBUrP2ik6nZyDtuH2k6ZTjZxubiTS37Ke4Fo4tIK7hoarMAJgjwcJko3y3M3aQCOb\n3IkDDDh03GKEqzACgNwavjjorImPovAwwI4qEsChz1ocjVFPGaD9tfLUy3YD9GW9lCFKJ25YjOD0\n4WQZ+bAs8yV4LfMsKK3Jlm9oJZRG/Eys4M8q8BP+R0R6TLYqxpaljf5s2p9UYPVPBUFTpCVDtuAf\nEcr7xH4froTxzkrGzpHWQLZsvNEmzS+AdBPIFl+sjY2muOORlgogW1yxRrIREjnOFKRfdHX17TQ4\nWo0UXhFRjoVDb7JqLMcb/nJhvofDO3R9EBajpdIax4LS2mLR5Ij/kfoLzgzy5MB/1+MAAAAASUVO\nRK5CYII=\n",
      "text/latex": [
       "$$1 - \\frac{x^{2}}{2} + \\frac{x^{4}}{24} + \\mathcal{O}\\left(x^{5}\\right)$$"
      ],
      "text/plain": [
       "     2    4        \n",
       "    x    x     ⎛ 5⎞\n",
       "1 - ── + ── + O⎝x ⎠\n",
       "    2    24        "
      ]
     },
     "execution_count": 74,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s1 = cos(x).series(x, 0, 5)\n",
    "s1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAF8AAAAcBAMAAAD1rn4EAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAEHarIkSJZt3NVLsy\nme8Q6PJIAAAACXBIWXMAAA7EAAAOxAGVKw4bAAACCUlEQVQ4EY1Sv2tTURT+Xsx7SV5+9FKh0MnX\nCm61obhYB99SHBv8A0wUwbFO6qJDUcShtCiCwcEIuuhglg7i0Afi4CBJ7SDSwS4OTiYiCCLEc867\n971cSfFdOOd833fOx7l5N0DG4+3vZpzUY5dxOpvhnR67jV6Yy2CpdPXQHaw23Pr/HSWVzLxSuJKQ\nf4C7O7P5ULSPaWcdKKb2VGe04G5/GDUI5IdJw+sDOYpJ50hwQWFxi1o8pc9NqvmBYVL9QNM95ysw\nxc1aR0twW24E3DVUqjG4w2oXKPFtespMvH/xkvC+oZah2PeJl3nDrWTg+2hE+CTF9PGVE4HoZkMz\nYlo+oPSZwpk/df4SVT5NBadVWC9uCTOGL3KPWp/ENxQzuBHckwG6YgRPeUM/FG4MO8J6DSoPKC5i\nTT0TCfTacFDqMvPa7Uff2u06wSeKhdecNigUHjOUs9qhMhUIBsyGsxEJlZ+s8gbgh2ROtEHuFQvG\nsMZrZrkVGyp/4j7lXghfLSInd0g2HPtFb7otQ2coP80NMKct9JWanR2ci6nZUBgtr+yFotF3d3+X\nB/mr2kDvcnR++pOmxoC3mxtRPMHffWlu4bqeP+SlTZdqTX5JKtxPISEntCiTasuSnPTfbukpqRyk\nmFChbtFJZNkSi5FFJ5FZS7xmsYnE74/J+e4YOQw+H2tU1RjJCv8Cl4Bl3Hr5MZEAAAAASUVORK5C\nYII=\n",
      "text/latex": [
       "$$x + \\mathcal{O}\\left(x^{2}\\right)$$"
      ],
      "text/plain": [
       "     ⎛ 2⎞\n",
       "x + O⎝x ⎠"
      ]
     },
     "execution_count": 75,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s2 = sin(x).series(x, 0, 2)\n",
    "s2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAF8AAAAcBAMAAAD1rn4EAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAEHarIkSJZt3NVLsy\nme8Q6PJIAAAACXBIWXMAAA7EAAAOxAGVKw4bAAACCUlEQVQ4EY1Sv2tTURT+Xsx7SV5+9FKh0MnX\nCm61obhYB99SHBv8A0wUwbFO6qJDUcShtCiCwcEIuuhglg7i0Afi4CBJ7SDSwS4OTiYiCCLEc867\n971cSfFdOOd833fOx7l5N0DG4+3vZpzUY5dxOpvhnR67jV6Yy2CpdPXQHaw23Pr/HSWVzLxSuJKQ\nf4C7O7P5ULSPaWcdKKb2VGe04G5/GDUI5IdJw+sDOYpJ50hwQWFxi1o8pc9NqvmBYVL9QNM95ysw\nxc1aR0twW24E3DVUqjG4w2oXKPFtespMvH/xkvC+oZah2PeJl3nDrWTg+2hE+CTF9PGVE4HoZkMz\nYlo+oPSZwpk/df4SVT5NBadVWC9uCTOGL3KPWp/ENxQzuBHckwG6YgRPeUM/FG4MO8J6DSoPKC5i\nTT0TCfTacFDqMvPa7Uff2u06wSeKhdecNigUHjOUs9qhMhUIBsyGsxEJlZ+s8gbgh2ROtEHuFQvG\nsMZrZrkVGyp/4j7lXghfLSInd0g2HPtFb7otQ2coP80NMKct9JWanR2ci6nZUBgtr+yFotF3d3+X\nB/mr2kDvcnR++pOmxoC3mxtRPMHffWlu4bqeP+SlTZdqTX5JKtxPISEntCiTasuSnPTfbukpqRyk\nmFChbtFJZNkSi5FFJ5FZS7xmsYnE74/J+e4YOQw+H2tU1RjJCv8Cl4Bl3Hr5MZEAAAAASUVORK5C\nYII=\n",
      "text/latex": [
       "$$x + \\mathcal{O}\\left(x^{2}\\right)$$"
      ],
      "text/plain": [
       "     ⎛ 2⎞\n",
       "x + O⎝x ⎠"
      ]
     },
     "execution_count": 76,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expand(s1 * s2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "If we want to get rid of the order information we can use the `removeO` method:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAG8AAAAwBAMAAADtMzlxAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAEHarIkSJZt3NVLsy\nme8Q6PJIAAAACXBIWXMAAA7EAAAOxAGVKw4bAAACRUlEQVRIDc2Vv2vUYBjHv8klubt4XsMVOqdV\nCg6HtS3oIJhBORfx8B/o6XCLSG/TSQ8VsTjo2MOhFR0VuiuYyU0aFNqhFBwVRe78hagYn8vv5p6n\noA76Dnmf5/t9PnnfhDxvgGBUjjY6YZS/GvVDeSmb6/7HbJqJN7GVyUZC/aE1ooXCBq4ITiDrTdnd\nfcUXdWlJ5Z18T0BrFtcE/4AtGJFc+ST5u261YCmfJXB9VXJIrzragLXpCU93WCcUDcvwePs6Lguv\nrbbvxLSN9sYIp0zNnzmHZ9PzI04gKK3i1dIdzpvAJXuJM0KNNjkwHc4/i0XrAWeEmoLyGu9auMsb\nsTpmx1F+/pAXdubr7s48ySo/kpAJTOsgVPaF31P7mGSISFpYfYoGZ+vf9vS1DueE2vhUbZO1ldnJ\n+kWZ+78d0/7D/f07MOyn39h2tFW5n6R7RWDUT346CFCWb9JYcikcS40+pUavt/ym15uhGrGfqIwd\nyVuV+4nlkIBiP/FcDMr9JHAxKPaTxMVg3E+ntp4MS59z9dr2YzfVk2cMJGUGi02KbqUFaTQOI/Nn\nUJzUAQoWqq8A9W1WjGP6i7+P4/xc7aJAh1KDPQpfA8fcPBHl5UEAtlhwxZJB4ksDFB0WJPO2JaxI\n8kILNenU1r/IHK4BLQks0Vctjb0eTFcCtyWK9DowAQFUPRk0PRy/Pzf3c5YreQTN4fShRt/afprY\nD6DiQXXI5IZ2o/2yS8Z3zjzZvnCE04damU6ILnDeP8xUrPj+V0b+K+kXPYuKl+Zu0xMAAAAASUVO\nRK5CYII=\n",
      "text/latex": [
       "$$\\frac{x^{5}}{24} - \\frac{x^{3}}{2} + x$$"
      ],
      "text/plain": [
       " 5    3    \n",
       "x    x     \n",
       "── - ── + x\n",
       "24   2     "
      ]
     },
     "execution_count": 77,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expand(s1.removeO() * s2.removeO())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "But note that this is not the correct expansion of $\\cos(x)\\sin(x)$ to $5$th order:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAANsAAAAwBAMAAABqLhIyAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAEHarIkSJZt3NVLsy\nme8Q6PJIAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAEdklEQVRYCb1XXWgcVRQ+s5n9/xsSKPSl2aRF\nn2K3IqgVdR6M+lKzCIIodbcpRF9i9skKggSFah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fiOpM6B65D/cYflSW9KB74nL68fMbxMbbOxM4Ru6s8OfeVpMz1CM1OFH4i\nW3mvS94/GIb0fm6EnNmC883Qxf3BFrwcvuyWXLcRQhLtw0WBRsSgfhQmhVYCe9Ri6MrWWBtTsycP\nyWjUK2xLSJo9s7qRvAnjKzoSElhuRMsScZQMb844ktvjyDdTovsrt1/KeU3yehzjdA/EAa/cqSmH\nA0oj1xJgc11wek3zlc1ekBBWLm+Z4WclEfL8qeAWLcFRma/WVKiHsXI4vvDO/9Gp1PNpx4WDctdt\njuzRwPfyfM93Mtdk5R4G4ROeM0Ma5e5u5W4B+K17yApSWmkdMl7XklBy2NXhY7dE/p7ndBPOV7Qq\nrNwxSN/QBgxMHN/yu5YqsfjYXw+CefXR3Z5tVe7/iP0Lu0QQYvWiWkQAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$x - \\frac{2 x^{3}}{3} + \\frac{2 x^{5}}{15} + \\mathcal{O}\\left(x^{6}\\right)$$"
      ],
      "text/plain": [
       "       3      5        \n",
       "    2⋅x    2⋅x     ⎛ 6⎞\n",
       "x - ──── + ──── + O⎝x ⎠\n",
       "     3      15         "
      ]
     },
     "execution_count": 78,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(cos(x)*sin(x)).series(x, 0, 6)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Linear algebra"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Matrices"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Matrices are defined using the `Matrix` class:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [],
   "source": [
    "m11, m12, m21, m22 = symbols(\"m11, m12, m21, m22\")\n",
    "b1, b2 = symbols(\"b1, b2\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAGgAAAAyBAMAAABCJ4MDAAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMA74lUMhBEqyJ2u93NZplQnf8bAAABo0lEQVRIDe2WsUrDUBSG/zZprNaKqIuT2cSlUnyAKta9g3uL+ADiplPBxc1OgpuLgosUn6Dgg+jm0A5VsHaL99xr7vUkp0PqJPTAhXD/+5Hwk3wEG9EHMs129I7V+kEmBof1KtayIXR6bwaZ0nQRweblzVmwdS/1KGUayi88oHmNKuDfmuVwnlUeGyrS0H6ph6sQL/Dfuno5BizLt+d6MdRotlBr4BzwumY5imWltj+OIdSAPrAuQSzLtYojCw2AJwTjgnAnsAzep4VWUBhhqXchQSxDqRND6p7lIRbDUIB4hopiTHtBF/Mn8E53BYhn5VcL0YWZdHtxYko6wrHaSHwa3rIK1ZJG7fvPO3cpqNj/6tCSGNrPRdEwBUmHhb3E4wknhK0Z9FPKrIg/FyEJMX7lpExX7oRIMiRhuuGZJEuSIQnz11hZUibKUsuQPnk3VpaUibLUMuSQlSVlsixJhgnIylKLUpIlyTABWVlqUUqyJBlyyMlSi1KSJcmQQ06WlImyJBlyyPVImSRLLcMJsqRMlCXJcJIsKfsvspzq122an8Rv50XFB+Ww4SIAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$\\left[\\begin{matrix}m_{11} & m_{12}\\\\m_{21} & m_{22}\\end{matrix}\\right]$$"
      ],
      "text/plain": [
       "⎡m₁₁  m₁₂⎤\n",
       "⎢        ⎥\n",
       "⎣m₂₁  m₂₂⎦"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "A = Matrix([[m11, m12],[m21, m22]])\n",
    "A"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAB4AAAAyBAMAAAC5cHbcAAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMA74lUMhC73c2rRHaZImaqCQggAAAA9klEQVQoFWOQ//+JAQb0/39kEHZxhXEZQlwMGUTgPBDDEcRnTSyACYL5DBwTUPn8Bqj89QGofHUYF2IeQ+fuw1ARiPk/AvgvMLiBhMB85q8M/Ao+0+F8ngaGeAUGczif4wDDegMkPv8DhvMByPwFrHIMSHzOB2wHkPmsp+cBzUKYB+Rg4RuCBCH+BbHu1M9G4YPEkOXpyKdLfDAdOwrzHzg+dBlmwPjg+Khl8L8A9T84PqQY7i+A8iHxwWAPTAXg8OMHxwdDNUw/JD6YDsD4kPh4A+QihTeXApcDMt/D2AxmHkghg/z//0ASET9gQSL46OkdLT8AABDBTMmz6EtEAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$\\left[\\begin{matrix}b_{1}\\\\b_{2}\\end{matrix}\\right]$$"
      ],
      "text/plain": [
       "⎡b₁⎤\n",
       "⎢  ⎥\n",
       "⎣b₂⎦"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "b = Matrix([[b1], [b2]])\n",
    "b"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "With `Matrix` class instances we can do the usual matrix algebra operations:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXIAAAAzBAMAAAB4eZ5HAAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMA74lUMhBEqyJ2u93NZplQnf8bAAAFXUlEQVRoBdWav4tcVRTHv/Mzq+suQUUQhEwhqCAxSwpRiyQYGxGdwsIuw2InolgZtRhIExuzlUGrNApay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5NgFsjX8+cg+N8cHWXKgj5PZRl18Bk3sjxiucnffcOz1eMRsUA5/kFc7MHzHKxlUsxuRqxGSzQhXqXqTyyOTi9IhBZBT1ftK69EuSDnOaErlQ2EfdWI3JxYgRs0IU6l7JvggLErk6Pdkgsop6P4Zckw5zmhK5UJgyKWByMWLko5Ao3L3oQxWPRK5OTzaIrKLeT1oXf2kSfWKlJFVyoZiZyIWCDbnaswuTG2uG6UXh7hXJS5aRGERiIpGSvB+DTYEkETkniSKFipZRxZSTopF8zxlEolD3qu95xenJBpF6P+z7ZO9HrsMTTeLP2s1OU9pzsYwqppxUjORixBAjc4pC1owj74lllA0iq4j3I9fhiSYx+fVGpymTZ4qKKScVmVyNmEyuCtkyjlydnmwQWUW8H7kOTzSJyClJlVyIExN5hYKeW+yzC5OrEZPJVaHu5cjV6ckGkVXE+2EO+aFJRE5JquRCnJzIlUJNOSkW7xYJM7kIbM04cjntDSJS1PuRxNokkNskWyjfLbpKTDmR6uTBqDBmBdsyojjLyBtEpFgTSa5VmRiDiHRbyFlGaspJEUvuzQrqXgfYF94gIsWaSHItnXiDyBfS7DCj55bas4slN9ktCiqmnFB1g7xiynWMXHArk3Plb4lUMto5pW+JFL+Z007cClX4Zs5fZLuVy5E1BG0AAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$\\left[\\begin{matrix}m_{11}^{2} + m_{12} m_{21} & m_{11} m_{12} + m_{12} m_{22}\\\\m_{11} m_{21} + m_{21} m_{22} & m_{12} m_{21} + m_{22}^{2}\\end{matrix}\\right]$$"
      ],
      "text/plain": [
       "⎡    2                               ⎤\n",
       "⎢ m₁₁  + m₁₂⋅m₂₁    m₁₁⋅m₁₂ + m₁₂⋅m₂₂⎥\n",
       "⎢                                    ⎥\n",
       "⎢                                 2  ⎥\n",
       "⎣m₁₁⋅m₂₁ + m₂₁⋅m₂₂   m₁₂⋅m₂₁ + m₂₂   ⎦"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "A**2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAJEAAAAyBAMAAACufiRQAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMA74lUMhC73c2rRHaZ\nImaqCQggAAAACXBIWXMAAA7EAAAOxAGVKw4bAAACnklEQVRIDe2Xv2sTYRjHvya5Jj3TJqjgIOht\nKnaoOHRwqNAKDg7n4qQEBxftEP0HPBAhBYdOdQhIKO7tbDsEHFoRasBVMf+BJaWggXg+z/O+6f16\ncx6mk+0LB+/7vN9+evfcm3wILvk9jD1yvl/F2cXbY4NgLS5UcW58DhMKQrIe1TPh7p8fHVMklFZG\nR8I7y+FFdK5JldloOb66qQv78Y1grUnrblAyzTTJPjBtqpomXR6dkB1NyqW0U5OWNz/IX9hXv202\n7WtP4mBNKjW3VBsMOUWyfrq1Du4AuYmnqL3HdXqpnroUU5Nqr6wBZpbcWI4r+hTkD1Bx7r4BFooe\nvjv4gcLHulwKBE2ad9HLdSa9aE4qmlT2UHMwB7i1Fii+CuSpJXzRuNJoPGs0+ADswOoVO4VBNCcV\nTSq1sT7LJMwD28CFCInK+p5ew94vtqb60ZyqqD5VuvjsCmkHeA57YIXvKSD9RpnOAfWC7i6Uk4om\ntayLENIZWH2UvS9mUh/3ukBxA4jkpKJIk92JtpDoxqf3UHIcM+ktlgDMANEcV4af4E+7NKc+2XWc\nXkF+95aZ9GCrC0y34zmuaBJNaHDHD0fo3VFNd1x21/DuMKXejFTU06kdOo/ByFcpRZcaD4cT+t8v\nbzwOVpxRlRDp64tmkJja/rXBV1AZzk75/t5wTg2jjKqESMH2P81OSNnadhz6dGJOPgv/jTnZhgWP\nnkiG/qYzmJNzqeZkG7I9o6SkOTmXbk6xYQZzci7dnGJDTaL70k+XNCfn/mJOtmGCZDCnWJNdqr4L\nKklzsg0TJIM5xZrsUkUymJNtmCAZzCnWTDUn2zBBMpiTc+nmZBsmSHImoubkVao5xYYZzMm5dHOy\nDbOYk3PHxJxH96vsyH4p/gHeHTH4ApAfnQAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$\\left[\\begin{matrix}b_{1} m_{11} + b_{2} m_{12}\\\\b_{1} m_{21} + b_{2} m_{22}\\end{matrix}\\right]$$"
      ],
      "text/plain": [
       "⎡b₁⋅m₁₁ + b₂⋅m₁₂⎤\n",
       "⎢               ⎥\n",
       "⎣b₁⋅m₂₁ + b₂⋅m₂₂⎦"
      ]
     },
     "execution_count": 83,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "A * b"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "And calculate determinants and inverses, and the like:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAKYAAAAMBAMAAAAaIdvMAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMARImrIna7EFTvMt3N\nZpneUCSWAAAACXBIWXMAAA7EAAAOxAGVKw4bAAABq0lEQVQoFWWTsWvUYBjGf0mvvVxij3CjDgbU\ntTh4Xexwg4KTvVJ01kHdSv4AoZ2kUugVwdmOHYqeopOCoVPpn+BghUIdesKdVhyv7/udfm9iH3jg\ne35JHt43IQRXbt1rB9ce4nWe+Et6aN24vdxt3U8NniPhzCNWl3gOcTGxkbmVHHVF2eNu/XcabcEu\nhMffwROXhO4kBYsZh8RHfWcjYWeqUFcq47VP1H4yO+T1TbjKAkY0Kc1XU3o58xD1J/Yk6cSnau18\n+lF1APX6iOgPUw9gA97zpmNEk1J6cAIvrdOTJK2N1HJTSdGQZp9G13W+ZTHFE5e0cwDvCE7rfk4j\nOpBzqZJmQZJxuZO7iXRHI5q08wWyTbO4Y52ekMg06rIaGfK6BrW1SecHMIIk6ZTV5H1fyDLfaYQ5\nKVOXJcsewl7onib8hq7/l2iSzqDP9HWiH9u+08is3KKu6BIsw+aXSedXuWZEk+7u9e+7e0CLi85G\nKiedKAu2jblU7dySDyL2ivfXn6g9+O8g/8nu+rPcqEtCvWonv7pqD2iMx0O1kcrp7uc2r8bjEtMk\n9AyNtKqM6qgiUQAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$m_{11} m_{22} - m_{12} m_{21}$$"
      ],
      "text/plain": [
       "m₁₁⋅m₂₂ - m₁₂⋅m₂₁"
      ]
     },
     "execution_count": 84,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "A.det()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAVQAAAA1BAMAAADsYw7NAAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMA74lUMhBmmXa7RKsi3c0MJ4w/AAAD5UlEQVRoBe1az2sTURCe2qTWNm0Fe1OwCh48Wf8AIZUKPQYRFAT1IIieRMGTB2+2iNiDHgQP4lXEIhQ85tKThwa81h9/QIUoqCBInNl9szs72c17m/eijXQum++9mW+/vA2Zj0ngcOcbDEGc6HyFA4tnLErH7izdH1+pW7L62nanPrd4Emat9xh7fWVkfXwNTh9vVo4+s6aXSWBqWAcr9YKD1I2HMPN87xysTrT2wasySqy5TP3iEFipXaTCW1iAqXn4XP0+DZcb1vuXSTDUsAVWaieps7ACmxWA0RbAqTJC7LlMvYWpFmoXqbU2nuv1PQCXmlDdtt++REZCjVJt1C5SJ9ZgG94dg+o6wMWwz5+p8QNgpXaRyqd0fmOuevcso7DXLbBSl5H6qdOa6vwOK9GwLf2ct1KnUjve0VbvovrlA8bHOsx4U3eQOpWq7rPz4K7UQTyT3VMd7KkqP6agufe1q8s3lx8nQhRM1vULladgnK0WFcSc9AMg/BhMNoBh1vnd+AEHGw+AEnADDIz8G7aywhBlaPdkGbHEIXLyqVOpwo9NHGkCw4zzq11owS+4BZSAGwzJv6GNKwzOozLMY0hlyBKX8WIxdSqVrR6146kmMDTOb/QpxhOYvFfZD++jBNxgGPk3LCsMUUb0BlIZsrhSC6nCj5FUhhnnN1IfX62169F7wQ2G5N96SeU84sU8hlRG9FHwIuXkUqdSpR/D9ARmnN8mnsjY6lwkFTcYkn/rJZXzjFSGVIYscfAi5eRSp1KlH8N0hlnn9xKmm7U3DZJKGwzJGvaSynlGKkMsI5Y4eLGQOpXKJXRPojSR7/wwATc4J/JvvaRyopFqIJUJFrNaSN0tFf1Y5dFtJodc50cJuMFJ5N+wjGHhlcpEHpUJlrismLpbauGN/vXGfyg1v896HXRZStdTFX2WumqIYEpqtS6UrlJFn6XWFyKYElutE6WrVNFn5VeZl+R0suJE6SxV9FnxresllSmzX+SFlK5SZZ8NJDWhDCxV9tlAUplStUfvU2UCaoSBpDLloKRiI5RtN7mdxwvVyQuZXD+rhQR/byOSmkxs/Ac2bS09zBCIWIftVPVJ7Ey8e6qDeC5De6rKQipojkqNaBTsOk+1r2CcrhYVNJTZU1UWkqHXMEgMePofApHarFRlIRn6DIPkgKf/IVC3VHal3JazPwO6TmzMAzOXIEOgHKnKQjL0GQbJAQ/aPYblhkCxVPkju7KQCfQZBskBD0plWG4IBEA/ssu/LigLydBrGCQGPPS5YlhuCARAf13IjawxDzIMIpeLtCZKDoG4rPuqLGSIYZDfEKhb4s5e+QMte6UY83QawgAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$\\left[\\begin{matrix}\\frac{m_{22}}{m_{11} m_{22} - m_{12} m_{21}} & - \\frac{m_{12}}{m_{11} m_{22} - m_{12} m_{21}}\\\\- \\frac{m_{21}}{m_{11} m_{22} - m_{12} m_{21}} & \\frac{m_{11}}{m_{11} m_{22} - m_{12} m_{21}}\\end{matrix}\\right]$$"
      ],
      "text/plain": [
       "⎡       m₂₂               -m₁₂       ⎤\n",
       "⎢─────────────────  ─────────────────⎥\n",
       "⎢m₁₁⋅m₂₂ - m₁₂⋅m₂₁  m₁₁⋅m₂₂ - m₁₂⋅m₂₁⎥\n",
       "⎢                                    ⎥\n",
       "⎢      -m₂₁                m₁₁       ⎥\n",
       "⎢─────────────────  ─────────────────⎥\n",
       "⎣m₁₁⋅m₂₂ - m₁₂⋅m₂₁  m₁₁⋅m₂₂ - m₁₂⋅m₂₁⎦"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "A.inv()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Solving equations"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For solving equations and systems of equations we can use the `solve` function:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAEoAAAAUBAMAAADYerbFAAAALVBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADAOrOgAAAADnRSTlMAdt3NMolEEFTvq5lmIsfa\npuIAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAB3SURBVCgVYxAyYSAEDqsxhBFSA5QPQ1bFMR2Ljs4C\nVFVVu55jqGJfvQ5NFQMjpioGBrlBrqpYCQSAgTuYXV9ngBb+6KHKvfLxGgYmdVRVu+ZZHUCNbbB8\nL6oqMA8lTYBFAohRxS5AjCoeLIqA7hJSwSaOIiakBgD0ZimSClhTrgAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$\\left [ -1, \\quad 1\\right ]$$"
      ],
      "text/plain": [
       "[-1, 1]"
      ]
     },
     "execution_count": 86,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "solve(x**2 - 1, x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAjEAAABLCAMAAAC2lyZIAAAAPFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAo1xBWAAAAE3RSTlMA\nMquZdlQQQOkwRM3du2aJ7yJs4cVMPgAAAAlwSFlzAAAOxAAADsQBlSsOGwAACPhJREFUeAHtnOna\noygQhYkmTk8WTcb7v9fBpUpFwTosytNJfjSYTlEvh/MpIom6tP2rUPJXM4Sk+FcOYXwyBczQppHI\n4zCiXnD2iLlJjktbXvXrBrA8gc8e9dEcmajvZ7LFy113NilapS7thXomLR/SDx74uRyZqPtnskXO\nXXs55lKSFPmUOTKROmeyxc7t55i6Ji3yKXNkInXOZIud288xJXwZI+3SlTkyUW/PZIud288xkS+N\nJGxQmSMTdehMtti5/RwTb/pNmoaXOTJRr85ki53byzEfZOmGVEtc5shEXT6TLXpuL8fcrqRFPmWO\nTKTOmWzRc3s5prmTFvmUOTKROmeyRc/t5ZhXRVrEKD/X2fq+d4ORmWIgcV/C2D5BLIG512Pj5Zi4\nk6kiyhkrRyayTBhbmD7Rc/s4pnqRFDHKT5TbvxyZSJ0wtjB94uf2ccy9IS1ilCXyBNSaMEcmgg1j\nC9Mnfm4fx0BPuUk2W1n1p83HtVKXEG3iMwUjcY+D2Hp9/FnCcysjuY9jig+LYVZub3RSPNjk3c3u\nQk5ddiYcSfVMwUiszcR2PEt4bmUI4eMY22SqKsqiBR0znGLUoymudh+y9vaKhckHSY2nvVAkhh3Z\nTmEJz22OjY9jHFPVK+qYZngKHryIbGeCkdTAFIzEjpnYjmcJz60MITwc49pwgUoynmJMKhZbWnEw\noUjjKSYYidFnbIezRMhtCuHhGNeGC1SS67jRpqjra8hjeQcTiqRGplA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Y27OzTGk07FljkykwJlsCXMDjrHvFSONji9zZCIV\nzmRLmBtwDCnxK79agZ9jvnr4PTr/c4yHaF8d8nPMVw+/R+d/jvEQ7atDfo756uH36PzPMR6ifXXI\nzzFfPfwenf85xkO0rw75Oearh9+j84Nj+q1QO/ulPBr/hfxdCjyHLXP6ywrX/uXx0zB/lyC/3uwo\nUA9GUf8DYe6QJALMc1YAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$\\left [ - i \\sqrt{- \\frac{1}{2} + \\frac{\\sqrt{5}}{2}}, \\quad i \\sqrt{- \\frac{1}{2} + \\frac{\\sqrt{5}}{2}}, \\quad - \\sqrt{\\frac{1}{2} + \\frac{\\sqrt{5}}{2}}, \\quad \\sqrt{\\frac{1}{2} + \\frac{\\sqrt{5}}{2}}\\right ]$$"
      ],
      "text/plain": [
       "⎡        _____________         _____________        ___________       ________\n",
       "⎢       ╱         ___         ╱         ___        ╱       ___       ╱       _\n",
       "⎢      ╱    1   ╲╱ 5         ╱    1   ╲╱ 5        ╱  1   ╲╱ 5       ╱  1   ╲╱ \n",
       "⎢-ⅈ⋅  ╱   - ─ + ───── , ⅈ⋅  ╱   - ─ + ───── , -  ╱   ─ + ───── ,   ╱   ─ + ───\n",
       "⎣   ╲╱      2     2       ╲╱      2     2      ╲╱    2     2     ╲╱    2     2\n",
       "\n",
       "___⎤\n",
       "__ ⎥\n",
       "5  ⎥\n",
       "── ⎥\n",
       "   ⎦"
      ]
     },
     "execution_count": 87,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "solve(x**4 - x**2 - 1, x)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "System of equations:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAH4AAAAVBAMAAAByPkciAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAZpkQ3Ynvq81UMrtE\ndiLw+n06AAAACXBIWXMAAA7EAAAOxAGVKw4bAAABrklEQVQ4EZ2UMUjDUBCG/+Sl2NI2uugqHcQu\nQiY7lSoiTpWAi4sguIgg1EFxDIK4Zupog6tDuzmI2KmbtFS0k6i7g1pEJ/HeS1KTl4iQGy69/97H\nXe5eCkApIJmd3XKOLSejieo45JTXBDybmSRWtQhNbZKTLLMlCXKYttkqoQukx/Cl2aEMSPEUsO6h\nMTzy//EXQMNwSyfiP4GuHeDLg5e7HvWo1USjMfXLc9DFVFboBHsnvufyYxbFplLV6Il57hDXv1lH\nnm+KbZPTP4Cm6a6u7tAgjNQw80QJz6L1dbuIbMvP61SfeBwB5zskMqRHOX4myjPsYrzn817/GKt6\nlyiQi+eRG6Lp+Dxofg0bOCGBvz9143DvW7Q+VAv3fhq4BKYN9/35JcoYj8gbv+kYPlsDLd03uj/F\nwP3p2td45rnA/CuWf1g81Vbujf8Q84dmM5qbuDrclR7KhQmedfevHnztQVviwsjYfv9bBHz/YBsD\nJ8CLhOxOJYEmINmovqS7oRlSD1FphwQKBP/X9896oeOLuArFPHA7Oo7oQlDC8k3fCQsUddpcyiT+\n/1sDfgDNr2XH9LJoSQAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$\\left \\{ x : 1, \\quad y : 0\\right \\}$$"
      ],
      "text/plain": [
       "{x: 1, y: 0}"
      ]
     },
     "execution_count": 88,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "solve([x + y - 1, x - y - 1], [x,y])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In terms of other symbolic expressions:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAOAAAAAmBAMAAAAvsop7AAAAMFBMVEX///8AAAAAAAAAAAAAAAAA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2L0anmbfgcuO/KYUGVgcob7Bpm\nXAsnsD0/tkT5CHCqeRveAV7G3FmobEYVe6yr3bgj69JZIrfGqeZt2GTIhv4lYeiuRSOlyKnmbcjq\nnDZoMfai53u2WFOKzGqFDAOqr9BO9wOjtlaJrGqFDBUbEihlrylFVjXTsEV5oH0KGuxRQIqUIqua\nadhIU3gcVtXOqpSUqURWNd38MzMeoTksXgctTrGvB3spk2KlyKoWMn+SgvyjhrTyHoTjhGE38JEy\nKVaJ7GpfRkx57QEprW5q8hmF2smp/mYKaawUWdV2HbXVZ+yJMzatrHx3AmviZ58PzRTSWCmyqu3g\n4r9Q1gIGAlZHdQAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$\\left \\{ x : \\frac{a}{2} + \\frac{c}{2}, \\quad y : \\frac{a}{2} - \\frac{c}{2}\\right \\}$$"
      ],
      "text/plain": [
       "⎧   a   c     a   c⎫\n",
       "⎨x: ─ + ─, y: ─ - ─⎬\n",
       "⎩   2   2     2   2⎭"
      ]
     },
     "execution_count": 89,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "solve([x + y - a, x - y - c], [x,y])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Further reading"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* http://sympy.org/en/index.html - The SymPy projects web page.\n",
    "* https://github.com/sympy/sympy - The source code of SymPy.\n",
    "* http://live.sympy.org - Online version of SymPy for testing and demonstrations."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Versions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/json": {
       "Software versions": [
        {
         "module": "Python",
         "version": "2.7.10 64bit [GCC 4.2.1 (Apple Inc. build 5577)]"
        },
        {
         "module": "IPython",
         "version": "3.2.1"
        },
        {
         "module": "OS",
         "version": "Darwin 14.1.0 x86_64 i386 64bit"
        },
        {
         "module": "numpy",
         "version": "1.9.2"
        },
        {
         "module": "matplotlib",
         "version": "1.4.3"
        },
        {
         "module": "sympy",
         "version": "0.7.6"
        }
       ]
      },
      "text/html": [
       "<table><tr><th>Software</th><th>Version</th></tr><tr><td>Python</td><td>2.7.10 64bit [GCC 4.2.1 (Apple Inc. build 5577)]</td></tr><tr><td>IPython</td><td>3.2.1</td></tr><tr><td>OS</td><td>Darwin 14.1.0 x86_64 i386 64bit</td></tr><tr><td>numpy</td><td>1.9.2</td></tr><tr><td>matplotlib</td><td>1.4.3</td></tr><tr><td>sympy</td><td>0.7.6</td></tr><tr><td colspan='2'>Sat Aug 15 11:37:37 2015 JST</td></tr></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{|l|l|}\\hline\n",
       "{\\bf Software} & {\\bf Version} \\\\ \\hline\\hline\n",
       "Python & 2.7.10 64bit [GCC 4.2.1 (Apple Inc. build 5577)] \\\\ \\hline\n",
       "IPython & 3.2.1 \\\\ \\hline\n",
       "OS & Darwin 14.1.0 x86\\_64 i386 64bit \\\\ \\hline\n",
       "numpy & 1.9.2 \\\\ \\hline\n",
       "matplotlib & 1.4.3 \\\\ \\hline\n",
       "sympy & 0.7.6 \\\\ \\hline\n",
       "\\hline \\multicolumn{2}{|l|}{Sat Aug 15 11:37:37 2015 JST} \\\\ \\hline\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "Software versions\n",
       "Python 2.7.10 64bit [GCC 4.2.1 (Apple Inc. build 5577)]\n",
       "IPython 3.2.1\n",
       "OS Darwin 14.1.0 x86_64 i386 64bit\n",
       "numpy 1.9.2\n",
       "matplotlib 1.4.3\n",
       "sympy 0.7.6\n",
       "Sat Aug 15 11:37:37 2015 JST"
      ]
     },
     "execution_count": 90,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%reload_ext version_information\n",
    "\n",
    "%version_information numpy, matplotlib, sympy"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
